我正在尝试编写代码,但只有在用户接受许可后他才按下发送分数按钮和流动代码。
第一次运行用户接受并收到错误的应用程序,第一次单击后它工作正常。
如何同步用户接受权限点击和其他代码?
public void post_Score(View view){
this.textView = (TextView) findViewById(R.id.editText1);
//request Publish Permissions
requestPublishPermissions(Session.getActiveSession());
Bundle fbParams = new Bundle();
randomScore = new Random().nextInt(1000000);
fbParams.putString("score", "" + randomScore);
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) {
System.out.println("BAD");
textView.setText("BAD " + error.getErrorMessage());
} else {
System.out.println("Your score is " + randomScore);
textView.setText("Your score is " + randomScore);
savingUserDetails();
}
}
});
Request.executeBatchAsync(postScoreRequest);
}
和 requestPublishPermissions 功能
private void requestPublishPermissions(Session session) {
if (session != null && !session.getPermissions().contains("publish_actions")) {
System.out.println("SEESION Permission");
Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(mainFragment, Arrays.asList("publish_actions"));
session.requestNewPublishPermissions(newPermissionsRequest);
}
}