0

サンプルコードから以下のメソッドでクラスを作成しました

private void publishStory() {
        Session session = Session.getActiveSession();
        if (session != null) {

            // Check for publish permissions    
            List<String> permissions = session.getPermissions();
                if (!isSubsetOf(PERMISSIONS, permissions)) {
                    pendingPublishReauthorization = true;
                    Session.NewPermissionsRequest newPermissionsRequest = new Session
                            .NewPermissionsRequest(this, PERMISSIONS);
                    session.requestNewPublishPermissions(newPermissionsRequest);
                    return;
               }

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

            Request.Callback callback= new Request.Callback() {
                public void onCompleted(Response response) {
                    JSONObject graphResponse = response
                                               .getGraphObject()
                                               .getInnerJSONObject();
                    String postId = null;
                    try {
                        postId = graphResponse.getString("id");
                    } catch (JSONException e) {
                        Log.i(TAG,
                            "JSON error "+ e.getMessage());
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Toast.makeText(getActivity()
                             .getApplicationContext(),
                             error.getErrorMessage(),
                             Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(getActivity()
                                 .getApplicationContext(), 
                                 postId,
                                 Toast.LENGTH_LONG).show();
                    }
                }
            };

            Request request = new Request(session, "me/feed", postParams, 
                                  HttpMethod.POST, callback);

            RequestAsyncTask task = new RequestAsyncTask(request);
            task.execute();
        }
    }

    private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
        for (String string : subset) {
            if (!superset.contains(string)) {
                return false;
            }
        }
        return true;
    }

許可行で次のエラーが表示されることがあります-

( session.requestNewPublishPermissions(newPermissionsRequest);)

java.lang.UnsupportedOperationException: セッション: 保留中の要求があるセッションに対して新しいアクセス許可を要求しようとしました。

このクラスにあるのは上記のメソッドだけです。何かを Facebook に公開したいときに呼び出します。のコードはLogin別のクラスにあり、呼び出されません。

質問は、なぜこのエラーが発生するのですか? UiLifecycleHelperコードの一部をクラスに追加する必要がありますか? その場合、どの部分を追加しますか?

これを別のクラスとして保持したいのですが、間違ったルートをたどっているので、パブリッシュを行っているアクティビティ クラスに組み込む必要があります。

御時間ありがとうございます

4

0 に答える 0