在Facebook中与描述共享图像

时间:2014-03-13 06:25:19

标签: android facebook

我想在Facebook上与Message分享图片,我尝试了以下代码,但它只会发布状态更新等消息。 将图像作为bytearray传递。

            String response = facebook.request("me");
        Bundle parameters = new Bundle();

        Bitmap bitmap = BitmapFactory.decodeResource(Radio.this.getResources(), R.drawable.ic_launcher);
        byte[] data = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        data = baos.toByteArray();

        parameters.putByteArray("picture", data);
        parameters.putString("message", msg);
        parameters.putString("description", "test test test");

        // parameters.putByteArray("message", );
        response = facebook.request("me/feed", parameters, "POST");
        Log.d("Tests", "got response: " + response);
        Toast.makeText(getApplicationContext(), "Successful Shared", Toast.LENGTH_SHORT).show();

3 个答案:

答案 0 :(得分:1)

我得到的解决方案只是替换为此代码。

        try {
        String response = facebook.request("me");
        Bundle parameters = new Bundle();
        Bitmap bitmap = BitmapFactory.decodeResource(Radio.this.getResources(), R.drawable.osho_shre_fb_t);
        byte[] data;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
        data = baos.toByteArray();

        // parameters.putString("picture",
        // "http://www.digitaltrends.com/wp-content/uploads/2013/04/Samsung-Galaxy-6-3-sample-image-3.jpg");

        parameters.putString("message", msg);

        parameters.putString("description", "test test test");
        // Bundle parameters1 = new Bundle();
        parameters.putByteArray("picture", data);
        response = facebook.request("me/photos/feed", parameters, "POST");

答案 1 :(得分:0)

您无法使用意图共享描述,您必须使用Facebook API与图像共享描述。

答案 2 :(得分:0)

您无法直接将图像上传到

POST /me/feed

端点,请参阅此处的文档(https://developers.facebook.com/docs/graph-api/reference/user/feed/#publish)或现有答案

你能做的是

1)通过

上传图像
POST /me/photos

2)并使用得到的照片id作为" object_attachment"的输入值。 Feed终点字段