Reputation: 5753
i developed an game
in this game users can login by FaceBook API then share there best score on facebook by score api.
but when i login in game by my Facebook account every things is worked and whene i login by other account i got this error:
(#200) Requires extended permission: publish_actions
and this my code:
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);
}
}
please help me.
Upvotes: 2
Views: 1059
Reputation: 5753
I solve problem by this steps:
Step1:
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();
}
}
});
Step2:
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();
}
Step3:
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);
}
}
Step4:
private static final int AUTH_PUBLISH_ACTIONS_SCORES_ACTIVITY_CODE = 103;
Upvotes: 1