我正在尝试使用自定义 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);