我正在浏览 Facebook
游戏教程,并且正在访问 part 5 - Publish Open Graph Story.这部分的重点是将分数发布到用户分数源。我遇到的问题是它执行代码,看起来没有任何问题,但没有在 Facebook 上发布分数。以下是应该发布分数的代码:
public void postScore(int score){
Log.d(TAG, "postScore");
Session session = Session.getActiveSession();
if (session == null || !session.isOpened()) {
Log.d(TAG, "SESSION == NULL OR IS NOT OPENED");
return;
}
List<String> permissions = session.getPermissions();
if (!permissions.containsAll(PERMISSIONS)) {
Log.d(TAG, "requestPublishPermissions");
requestPublishPermissions(session);
}
Bundle fbParams = new Bundle();
fbParams.putString("score", "" + score);
Request postScoreRequest = new Request(Session.getActiveSession(),
"me/scores",
fbParams,
HttpMethod.POST,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
Log.d(TAG, "error posting");
handleError(error, false);
}
Log.d(TAG, "successfully posted");
}
});
Request.executeBatchAsync(postScoreRequest);
}// end of postScore() method
其中权限定义为:
protected static final List<String> PERMISSIONS = Arrays.asList("publish_actions");
requestPublishPermissions() 定义为:
protected void requestPublishPermissions(Session session) {
if (session != null) {
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this, PERMISSIONS)
// demonstrate how to set an audience for the publish permissions,
// if none are set, this defaults to FRIENDS
.setDefaultAudience(SessionDefaultAudience.FRIENDS)
.setRequestCode(REAUTH_ACTIVITY_CODE);
session.requestNewPublishPermissions(newPermissionsRequest);
}
}//end of requestPublishPermissions() method
如有任何帮助、建议或建议,我们将不胜感激!谢谢!
最佳答案
Facebook 控制哪些内容作为故事发布,哪些不作为故事发布。当您反复发布高分时,Facebook 不太可能将每个故事都发布到您的时间轴上。如果您想要这种行为,我建议将消息作为自定义消息直接发布到时间线,而不是依赖分数 API 为您推送。
关于java - 分数不会发布到 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200195/