我在需要发布一些文章的项目中工作,我很难找到未经许可发布一些文本的方法但是我失败然后我决定授予publish_actions,我坚持这个错误
您需要在应用中使用列出的任何帐户测试此权限 在角色之前,您可以提交审核。它看起来像你没有 测试了此权限,因为没有针对的API请求 在过去30天内发布了._
搜索后我发现必须在授予之前测试此权限
List<String> mReadPermissions = Arrays.asList("email", "public_profile", "user_friends");
List<String> mPublishPermissions = Arrays.asList("publish_actions");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
_loginfb.setReadPermissions(mReadPermissions);
_loginfb.setPublishPermissions(mPublishPermissions);
_loginfb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
final Bundle params = new Bundle();
params.putString("fields", "id, email, name, picture.type(large)");
System.out.println("Success callback");
GraphRequest mRequest = GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject json, GraphResponse response) {
if (response.getError() != null) {
// handle error
Log.i(TAG, "ERROR");
} else {
Log.i(TAG, "Success");
String jsonresult = String.valueOf(json);
Log.i("JSON Result", jsonresult);
LoginWithFB(json);
}
}
});
mRequest.setParameters(params);
mRequest.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
但是我收到了这个错误
setReadPermissions之后无法调用setPublishPermissions 调用。
任何人都可以指导我如何授予我使用facebook sdk 4
的步骤答案 0 :(得分:1)
正如facebook docs
中所述,您无法将publishPermission
与readPermission
Facebook dev doc
根据文件
LoginButton只能与读取权限或 发布权限,但不是两者。同时调用setReadPermissions和 将导致相同的LoginButton实例上的setPublishPermissions 抛出异常,除非调用clearPermissions 之间。
所以在成功登录并获得Graph api
致电loginbutton.clearPermissions();
来设置PublishPermission
代码:
_loginfb=(LoginButton)findViewById(R.id.fblogin);
_loginfb.setReadPermissions(mReadPermissions);
_loginfb.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
final Bundle params = new Bundle();
params.putString("fields", "id, email, name, picture.type(large)");
System.out.println("Success callback");
GraphRequest mRequest = GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject json, GraphResponse response) {
_loginfb.clearPermissions();
_loginfb.setPublishPermissions(mPublishPermissions);
if (response.getError() != null) {
// handle error
} else {
String jsonresult = String.valueOf(json);
}
}
});
mRequest.setParameters(params);
mRequest.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
System.out.println(error);
}
});