我正在浏览Facebook
游戏教程,我正在part 5 - Publish Open Graph Story.这部分重点是将分数发布到用户分数Feed。我遇到的问题是它执行代码,看似没有任何问题,但没有在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
PERMISSIONS定义为:
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
任何帮助,建议或建议将不胜感激!谢谢!
答案 0 :(得分:0)
Facebook控制作为一个故事,而不是。当您反复发布高分时,Facebook不太可能将每个故事发布到您的时间线。如果你想要这种行为,我建议直接将时间线作为自定义消息发布到时间线上,而不是依靠分数API为你推送它们。