fails with this error in code : Publish permissions: '[publish_actions]' weren't accepted by user .
and then shows a facebook dialog with message You have already authorized
i printed all the permissions granted to my simpleFacebook object before calling the publish method which results in the above error
and i found that the public_actions wasnt granted before
how can i solve this
MY Code :
In Application class
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
.setAppId(getString(R.string.fb_app_id))
.setNamespace(FACEBOOK_NAMESPACE).setPermissions(PERMISSIONS)
.setAskForAllPermissionsAtOnce(false)
.build();
SimpleFacebook.setConfiguration(configuration);
In My Activity
private SimpleFacebook mSimpleFacebook;
private void loginAndPublish()
{
SimpleFacebook instance = SimpleFacebook.getInstance();
instance.login(new OnLoginListener()
{
@Override
public void onFail(String reason)
{
}
@Override
public void onException(Throwable throwable)
{
}
@Override
public void onThinking()
{
}
@Override
public void onNotAcceptingPermissions(Type type)
{
}
@Override
public void onLogin()
{
requestNewPermission();
}
});
}
private void requestNewPermission()
{
SimpleFacebook instance = SimpleFacebook.getInstance();
instance.requestNewPermissions(new Permission[]{Permission.PUBLISH_ACTION}, true,
new OnNewPermissionsListener()
{
@Override
public void onFail(String reason)
{
}
@Override
public void onException(Throwable throwable)
{
}
@Override
public void onThinking()
{
}
@Override
public void onSuccess(String accessToken,
List<Permission> declinedPermissions)
{
publishOnFb();
}
@Override
public void onNotAcceptingPermissions(Type type)
{
}
});
}
private void publishOnFb()
{
SimpleFacebook instance = SimpleFacebook.getInstance();
PostModel post = getPost();
String postText = post.toString(getActivity());
String imageUrl = post.getImage_url();
Feed feed = new Feed.Builder().setMessage(postText).setName("Yafda7to")
.setCaption(postText).setDescription(postText)
.setPicture(imageUrl).build();
instance.publish(feed, new OnPublishListener()
{
@Override
public void onFail(String reason)
{
// Fails here with "Publish permissions: '[publish_actions]' weren't accepted by user" without even
// showing a dialog for granting the permission from the user
}
@Override
public void onException(Throwable throwable)
{
}
@Override
public void onComplete(String postId)
{
}
});
}
MY Code :
In Application class
SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder() .setAppId(getString(R.string.fb_app_id)) .setNamespace(FACEBOOK_NAMESPACE).setPermissions(PERMISSIONS) .setAskForAllPermissionsAtOnce(false) .build(); SimpleFacebook.setConfiguration(configuration);
In My Activity
private SimpleFacebook mSimpleFacebook;
In My fragment
// Fails here with "Publish permissions: '[publish_actions]' weren't accepted by user" without even
// showing a dialog for granting the permission from the user }