Reputation: 21452
I am working in project that needs to publish some articles , I am struggle to find way to publish some text without permission but I fail then I decided to grant publish_actions , I stuck with this error
You need to test this permission in your app with any account listed in Roles before you can submit for review. It looks like you haven't tested this permission because no API request has been made against publish_actions in the last 30 days.
after search I find I must test this permission before grant it
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) {
}
});
But I got this error
Cannot call setPublishPermissions after setReadPermissions has been called.
any one can guide me how to grant steps I am using facebook sdk 4
Upvotes: 0
Views: 137
Reputation: 11545
As mentioned in facebook docs
you can't use publishPermission
with readPermission
Facebook dev doc
According to the doc's
The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.
so after Successfull login and getting response from Graph api
call loginbutton.clearPermissions();
to set PublishPermission
Code :
_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);
}
});
Upvotes: 1