1

我正在尝试使用自定义 opengraph 对象发布到 facebook。我在运行代码时没有收到任何错误,但也没有发布任何帖子。

我参考了以下教程的代码。 https://developers.facebook.com/docs/android/share-using-the-object-api/

这是我的代码。

// Check for publish permissions
        Log.w("FBShare", "Publish Story not null");
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            pendingPublishReauthorization = true;
            Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                    this, PERMISSIONS);
            session.requestNewPublishPermissions(newPermissionsRequest);
            Log.w("FBShare", "has permission");
            return;
        }
        progressDialog = ProgressDialog.show(this, "", "LOADING..", true);
        RequestBatch requestBatch = new RequestBatch();

        OpenGraphObject match = OpenGraphObject.Factory
                .createForPost("cricdecode:match");
        match.setTitle("My match");
        match.getData().setProperty("my_team", "Team A");
        match.getData().setProperty("opponent", "Team B");
        match.getData().setProperty("venue", "some plc");

        // Set up the object request callback
        Request.Callback objectCallback = new Request.Callback() {

            @Override
            public void onCompleted(Response response) {
                // Log any response error
                FacebookRequestError error = response.getError();
                if (error != null) {
                    dismissProgressDialog();
                    Log.w("FBShare", "error");
                }
            }
        };
        Request objectRequest = Request.newPostOpenGraphObjectRequest(
                Session.getActiveSession(), match, objectCallback);
        objectRequest.setBatchEntryName("objectCreate");
        requestBatch.add(objectRequest);
        requestBatch.executeAsync();

        OpenGraphAction playAction = OpenGraphAction.Factory
                .createForPost();
        playAction.setProperty("match", "{result=objectCreate:$.id}");

        // Set up the action request callback
        Request.Callback actionCallback = new Request.Callback() {

            @Override
            public void onCompleted(Response response) {
                dismissProgressDialog();
                FacebookRequestError error = response.getError();
                if (error != null) {
                    Toast.makeText(
                            MainActivity.main_context
                                    .getApplicationContext(),
                            "Error 1: "+error.getErrorMessage(), Toast.LENGTH_LONG)
                            .show();
                } else {
                    String actionId = null;
                    try {
                        JSONObject graphResponse = response
                                .getGraphObject().getInnerJSONObject();
                        actionId = graphResponse.getString("id");
                    } catch (JSONException e) {
                    }
                    Toast.makeText(
                            MainActivity.main_context
                                    .getApplicationContext(),
                            actionId, Toast.LENGTH_LONG).show();
                }
            }
        };

        // Create the publish action request
        Request actionRequest = Request.newPostOpenGraphObjectRequest(
                Session.getActiveSession(), match, actionCallback);

        // Add the request to the batch
        requestBatch.add(actionRequest);
4

3 回答 3

0

我猜问题出在这里: // 创建发布动作请求 Request actionRequest = Request.newPostOpenGraphObjectRequest(Session.getActiveSession(), match, actionCallback);

将其更改为:

// Create the publish action request
Request actionRequest = Request.newPostOpenGraphActionRequest(
Session.getActiveSession(), playAction, actionCallback);
于 2013-10-10T12:29:32.157 回答
0

问题是您在将 actionRequest 添加到批处理之前调用了 executeAsync()。因此,您只需创建对象但不执行任何操作。

将您的代码更改为:

    // Add the request to the batch
    requestBatch.add(actionRequest);

    requestBatch.executeAsync();
于 2014-08-22T13:53:36.323 回答
0

我猜你生成的指纹和哈希代码可能会有所不同。如果您仍然面临同样的问题,请按照以下链接从您的机器生成一个新的哈希密钥, Android-Facebook 应用程序的密钥哈希

将生成的 Hash 密钥放入您的 Facebook 开发者帐户中,然后重试。

于 2013-09-19T06:52:10.413 回答