我想将帖子发布到用户的墙上。我知道Facebook只允许测试人员和开发人员在墙上发帖。我已经将用户添加到测试仪列表中。当我尝试获得发布权限时,它表示用户已经授予权限(如屏幕截图所示)并返回。我无法获得许可或张贴在墙上。而且,回调的任何方法都不会被调用。无法获得测试用户Facebook的发布权限Android
CODE
我按照代码从Facebook例RPSSample。
//Publish to wall
public void publishResult() {
registerPublishPermissionCallback();
if (canPublish()) { //see definition below
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(urlToPost))
.build();
ShareApi.share(content, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
callback.didShareOnFacebookSuccessfully();
}
@Override
public void onCancel() {
// This should not happen
}
@Override
public void onError(FacebookException error) {
showToast(error.getMessage());
}
});
}
}
//check if user has permission or not
private boolean canPublish() {
final AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken != null) {
if (accessToken.getPermissions().contains(AppConstants.ADDITIONAL_PERMISSIONS)) {
// if we already have publish permissions, then go ahead and publish
return true;
} else {
// otherwise we ask the user if they'd like to publish to facebook
new AlertDialog.Builder(activity)
.setTitle(R.string.share_with_friends_title)
.setMessage(urlToPost)
.setPositiveButton(R.string.share_with_friends_yes, canPublishClickListener)
.setNegativeButton(R.string.share_with_friends_no, dontPublishClickListener)
.show();
return false;
}
}
return false;
}
//If user allows, ask Facebook to grant publish_action permission
private DialogInterface.OnClickListener canPublishClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (AccessToken.getCurrentAccessToken() != null) {
// if they choose to publish, then we request for publish permissions
LoginManager.getInstance()
.setDefaultAudience(DefaultAudience.FRIENDS)
.logInWithPublishPermissions(activity,
Arrays.asList(AppConstants.ADDITIONAL_PERMISSIONS));
}
}
};
//Callback - Any of the method doesn't call.
private void registerPublishPermissionCallback() {
LoginManager.getInstance().registerCallback(
callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken.getPermissions().contains(AppConstants.ADDITIONAL_PERMISSIONS)) {
publishResult();
} else {
handleError("Not enough permissions to publish");
}
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
handleError(exception.getMessage());
}
private void handleError(String errorMessage) {
// this means the user did not grant us write permissions, so
// we don't do implicit publishes
showToast(errorMessage);
}
}
);
}
我的应用程序在控制台上。请指导Facebook的要求是什么以获得测试用户的发布许可?谢谢。
从Facebook上删除你的应用程序,然后重试,它会起作用。 [如何从Facebook中删除应用程序](https://www.facebook.com/help/170585223002660)。重新安装后,它应该请求发布权限,而不是您已共享的屏幕。 –
抱歉,删除应用程序不是解决方案 – NightFury