【发布时间】:2013-04-24 19:06:10
【问题描述】:
我正在浏览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
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
任何帮助、建议或建议将不胜感激!谢谢!
【问题讨论】:
-
日志是怎么说的?
-
没有错误日志,但它确实命中了我放在代码中的日志,因此它发布到 logcat:
postScore和successfully posted。不过,在我的 Facebook 页面上搜索时,我发现它实际上没有发布 -
尝试使用图表浏览器 (developers.facebook.com/tools/explorer) 上的分数 API (developers.facebook.com/docs/scores) 读取 (GET) 应用程序的分数,并查看您的分数是否正确上传。另外,您的应用是否在“应用详情”设置中归类为“游戏”?
-
好的,所以我按照您的建议使用了图形浏览器,并且确实显示了我的应用程序中的分数。但是,我做了很多次,只显示一个分数,是不是只显示最高分?
-
好的,我注意到它确实只显示最高分。所以,看来我的代码毕竟是有效的。我现在的问题是:如果我发布应用程序,它是否只显示在代码、新闻提要和/或我的时间线上?
标签: java android facebook facebook-opengraph facebook-android-sdk