gpt4 book ai didi

java - (#200) 需要扩展权限 : publish_actions

转载 作者:行者123 更新时间:2023-11-30 11:10:29 25 4
gpt4 key购买 nike

我开发了一个游戏

在这个游戏中,用户可以通过 FaceBook API 登录,然后通过分数 api 在 facebook 上分享最好的分数。

但是当我通过我的 Facebook 帐户登录游戏时,一切正常,当我通过其他帐户登录时,我得到了这个错误:

(#200) Requires extended permission: publish_actions

这是我的代码:

public void postScore() {

final int score = getScore();
Log.i(TAG, "" + score);
if (score > 0) {
// Only post the score if they smashed at least one friend!
// Post the score to FB (for score stories and distribution)
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) {
Log.i(TAG, "onCompleted");
FacebookRequestError error = response.getError();
if (error != null) {
Log.e(TAG, "Posting Score to Facebook failed: "
+ error.getErrorMessage());

} else {
Log.i(TAG,
"Score posted successfully to Facebook");
}
}
});
Request.executeBatchAsync(postScoreRequest);
}
}

请帮助我。

最佳答案

我通过以下步骤解决问题:

第一步:

postButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Session session = Session.getActiveSession();
if (session == null || !session.isOpened()) {
Log.i(TAG, "Session is null!");
return;
}
List<String> permissions = session.getPermissions();
if (!permissions.contains("publish_actions")) {
// the user didn't grant this permission, so we need to
// prompt them.
askForPublishActionsForScores();
return;
} else {
ReadAndWriteFBscore.postScore();
}

}
});

第二步:

private void askForPublishActionsForScores() {
new AlertDialog.Builder(MainActivity.this)
.setPositiveButton("بله",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// User hit OK. Request Facebook friends
// permission.
requestPublishPermissions();
}
})
.setNegativeButton("خیر",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User hit cancel.


}
}).setTitle(R.string.publish_scores_dialog_title)
.setMessage(R.string.publish_scores_dialog_message).show();
}

第三步:

void requestPublishPermissions() {
Log.d(TAG, "Requesting publish permissions.");
final Session session = Session.getActiveSession();
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(AUTH_PUBLISH_ACTIONS_SCORES_ACTIVITY_CODE);
session.requestNewPublishPermissions(newPermissionsRequest);
}
}

第四步:

private static final int AUTH_PUBLISH_ACTIONS_SCORES_ACTIVITY_CODE = 103;

关于java - (#200) 需要扩展权限 : publish_actions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27680021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com