【问题标题】:Posting raw image data instead of URL to with Android Facebook SDK使用 Android Facebook SDK 发布原始图像数据而不是 URL
【发布时间】:2014-02-15 04:45:50
【问题描述】:

我想知道这是否可行,如果可以,我如何传输原始图像数据,而不是在发布到我的 Facebook 墙上时指定网络上图像的 URL?

我目前的工作代码导致:

http://1.bp.blogspot.com/-klSLFEmvHy0/TxpPMIay0xI/AAAAAAAAAKQ/iLZv-QtmThc/s1600/fbpost.JPG (对不起,我没有足够的积分来嵌入图片,所以请打开 URL :-)

这对于标题、标题、链接等来说是我想要的,但我的最终目标是让上面显示的心形图像成为我的应用在每次用户决定将结果发布到时生成的输出图像Facebook(内容在图像上动态生成)。我不想实现上传一些第三方服务器然后共享该 URL。

我见过周围有人提到这样的代码:

...
    byte[] data = null;
    Bitmap bi = BitmapFactory.decodeFile(imagePath);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();
    params.putByteArray(...

但这似乎是为了将照片直接上传到相册,这也不是我想要的。

到目前为止我的工作代码是:

private void loginAndPostToFacebook() {
    mFacebook = new Facebook(FACEBOOK_APP_ID);

    mFacebook.authorize(this, new String[] { "publish_stream" }, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            postOnWall();
        }

        @Override
        public void onFacebookError(FacebookError error) {
            L.t(getString(R.string.error_facebook_error) + ": " + error.getMessage());
        }

        @Override
        public void onError(DialogError e) {
            L.t(getString(R.string.error_facebook_error) + ": " + e.getMessage());
        }

        @Override
        public void onCancel() {
        }
    });
}

public void postOnWall() {
    Bundle params = new Bundle();

    // Message
    params.putString("message", "my msg");

    // Name
    params.putString("name", "app name");

    // Caption
    params.putString("caption", "caption");

    // Description
    params.putString("description", "description");

    // Here's where I'd insert my dynamically generated image data...       
    params.putString("picture", "http://4.bp.blogspot.com/-VaNzm3xMOtk/TxpKzhxpdEI/AAAAAAAAAKI/08Kc5b4HW0Q/s1600/sexometer128x128neutral_icon.png");        

    // Link
    params.putString("link", "http://www.stackoverflow.com");

    try {
        String response = mFacebook.request("me");
        response = mFacebook.request("me/feed", params, "POST");
        if (response == null || response.equals("") || response.equals("false")) {
            L.t(getString(R.string.error_facebook_error) + ": blank response");
            return;
        } else if (response.toLowerCase().contains("error")) {
            L.t(getString(R.string.error_facebook_error) + ": " + response);
            return;
        }
    } catch(Exception e) {
        L.t(getString(R.string.error_facebook_error) + ": " + e.getMessage());
        return;
    }

    L.t(getString(R.string.success_posted_to_facebook));
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (mFacebook != null) {
        mFacebook.authorizeCallback(requestCode, resultCode, data);
    }
}

【问题讨论】:

    标签: android facebook image facebook-wall


    【解决方案1】:

    据我了解,您需要先将照片上传到应用的相册。如果“no_story”参数为假,它会自动将其发布到墙上。

    https://developers.facebook.com/docs/reference/api/user/#photos

    【讨论】:

      猜你喜欢
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 2020-01-15
      • 1970-01-01
      相关资源
      最近更新 更多