4

drawables フォルダーからフィード ダイアログに画像を渡そうとしています。しかし、Facebook フィード ダイアログで画像を表示できません。残りのパラメータは利用可能です。Facebook SDK 3.5 を使用しています。フィード ダイアログを表示する関数を次に示します。

 private void publishFeedDialog() {


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

        Bundle params = new Bundle();
        params.putByteArray("picture", bitMapData);
        params.putString("name", "Facebook SDK for Android");
        params.putString("caption", "Build great social apps and get more installs.");
        params.putString("description", "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps.");
        params.putString("link", "https://developers.facebook.com/android");
        //params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");


        WebDialog feedDialog = (
            new WebDialog.FeedDialogBuilder(getActivity(),
                Session.getActiveSession(),
                params))
            .setOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(Bundle values,
                    FacebookException error) {
                    if (error == null) {
                        // When the story is posted, echo the success
                        // and the post Id.
                        final String postId = values.getString("post_id");
                        if (postId != null) {
                            Toast.makeText(getActivity(),
                                "Posted story, id: "+postId,
                                Toast.LENGTH_SHORT).show();
                        } else {
                            // User clicked the Cancel button
                            Toast.makeText(getActivity().getApplicationContext(), 
                                "Publish cancelled", 
                                Toast.LENGTH_SHORT).show();
                        }
                    } else if (error instanceof FacebookOperationCanceledException) {
                        // User clicked the "x" button
                        Toast.makeText(getActivity().getApplicationContext(), 
                            "Publish cancelled", 
                            Toast.LENGTH_SHORT).show();
                    } else {
                        // Generic, ex: network error
                        Toast.makeText(getActivity().getApplicationContext(), 
                            "Error posting story", 
                            Toast.LENGTH_SHORT).show();
                    }
                }

            })
            .build();
        feedDialog.show();
    }
4

1 に答える 1

7

公開フィードは、画像へのURLでのみ機能します。

pictureフィード ドキュメントの下のプロパティを参照してください: https://developers.facebook.com/docs/reference/dialogs/feed/

メモリ (drawable フォルダーなど) から画像を公開する場合は、次を使用する必要があります。Request.newUploadPhotoRequest()

これに加えて、SDK 3.5 をサポートするこのシンプルなオープン ソース ライブラリを使用して、写真の公開、フィードなどのアクションを非常に簡単な方法で実行できます: https://github.com/sromku/android-simple-facebook

アップデート

オプション 1
を使用できますRequest.newUploadPhotoRequest()が、この方法では、画像自体以外のプロパティを追加することはできません。

Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher);
Request.newUploadPhotoRequest(Session.getActiveSession(), bitmap , new Request.Callback()
{
    @Override
    public void onCompleted(Response response)
    {
        // ... handle the response...           
    }
});

オプション 2
説明などの追加のプロパティを画像に追加する場合は、ほぼ同じことを行いますが、生のグラフ API 呼び出しを使用します。の facebook 実装Request.newUploadPhotoRequest()はまったく同じことを行いますが、追加のプロパティを設定しません。

Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher);

Bundle params = new Bundle();
params.putParcelable("picture", bitmap);
params.putString("message", "This is the description of the image");
params.putString("place", "1235456498726"); // place id of the image

Request request = new Request(session, "me/photos", bundle, HttpMethod.POST, new Request.Callback()
{
    @Override    
    public void onCompleted(Response response)
    {
        // ... handle the response...
    }
});

RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
于 2013-10-02T20:02:40.580 に答える