我正在阅读Facebook
游戏教程,并在第 5 部分 - 发布 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
其中 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
任何帮助、建议或建议将不胜感激!谢谢!