Java (#200) 用户尚未授权应用程序执行此操作 android facebook SDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22224410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(#200) The user hasn't authorized the application to perform this action android facebook SDK
提问by Achin
I am posting on my wall in facebook sdk android but I am getting I'll post my code below
我在 facebook sdk android 的墙上张贴,但我得到我将在下面张贴我的代码
{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) The user hasn't authorized the application to perform this action}, isFromCache:false}private void postStatusUpdate(final String fbpost) { Log.d("postStatusUpdate",fbpost);
{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) 用户尚未授权应用程序执行此操作}, isFromCache:false}private void postStatusUpdate(final String fbpost) { Log.d("postStatusUpdate",fbpost);
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@SuppressWarnings("deprecation")
@Override
public void call(final Session session, SessionState state, Exception exception) {
if(session.isClosed()){
Log.i("postStatusUpdate session.isClosed", "message not posted session is closed");
}
if (session.isOpened()) {
Log.i("session.isOpened", "session.isOpened");
if (!session.isOpened()) {
Log.w("myConsultant11111111111","Session closed");
Session.OpenRequest openRequest = null;
openRequest = new Session.OpenRequest(TabActivity.this);
if (openRequest != null) {
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("publish_stream","publish_actions"));
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
session.openForPublish(openRequest);
}
}
Log.i("session.getPermissions() tab", ""+session.getPermissions());
//fbpostcheck = "if";
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
//session.requestNewReadPermissions(newPermissionsRequest2);
if (user != null) {
try {
Session session = Session.getActiveSession();
//session.requestNewReadPermissions(newPermissionsRequest);
if (!session.isOpened() && !session.isClosed()) {
// session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
// Session.openActiveSession(this, true, statusCallback);
Log.d("myLogs", "Test 1");
final String message = fbpost;
Request request = Request
.newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
@Override
public void onCompleted(Response response) {
//showPublishResult(message, response.getGraphObject(), response.getError());
Log.i("onCompleted", response.toString());
Log.i("getGraphObject", ""+response.getGraphObject());
showPublishResult(message, response.getGraphObject(), response.getError());
}
private void showPublishResult(String message,GraphObject graphObject,FacebookRequestError error) {
// TODO Auto-generated method stub
String title = null;
String alertMessage = null;
if (error == null) {
title = "Success";
alertMessage = "All is good";
//Toast.makeText(getApplicationContext(),"Posted successfully", Toast.LENGTH_SHORT).show();
AppMsg.makeText(TabActivity.this, "Posted to facebook", AppMsg.STYLE_INFO).show();
} else {
title = "Error";
alertMessage = error.getErrorMessage();
Log.i("alertMessage", alertMessage.toString());
AppMsg.makeText(TabActivity.this, "Error in Posting Message on facebook\n"/*+alertMessage*/, AppMsg.STYLE_INFO).show();
//Toast.makeText(getApplicationContext(),alertMessage, Toast.LENGTH_LONG).show();
}
}
});
request.executeAsync();
}
} catch (Exception e) {
// TODO Auto-generated catch block
Log.i("Exception user data", e.toString());
}
}
}
});
}
}
});
}
回答by Jatiendar Kumar
just open the permission dialogue with the publish_action permission then update your access token and then post your message
只需打开具有 publish_action 权限的权限对话框,然后更新您的访问令牌,然后发布您的消息
facebook Post on your behalf is not working in android facebook sdk 3.0.2