I used test app id and log on by test user create at dash_board app on facebook develop site, require pulish_actions permission when login using login button widget of facebook sdk but result get postid always = null. Here is my code:
....
shareDialog = new ShareDialog(MainActivity.this);
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
if (result.getPostId() != null)
Log.e(TAG, result.getPostId());
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});
pulishButton.setOnClickListener(this);
try{
loginButton.setPublishPermissions(new String[]{"publish_actions","publish_stream"});
}catch (FacebookException e){
e.printStackTrace();
}
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e(TAG, "success");
loginButton.setEnabled(false);
pulishButton.setEnabled(true);
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject json, GraphResponse response) {
if (response.getError() != null) {
// handle error
System.out.println("ERROR");
} else {
System.out.println("Success");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}).executeAsync();
}
@Override
public void onCancel() {
Log.e(TAG, "On cancel");
}
@Override
public void onError(FacebookException e) {
Log.d(TAG, e.toString());
}
});