Search code examples
androidfacebookfacebook-graph-apiandroid-facebookfacebook-permissions

Obtain Publish_actions permission facebook SDK 4.16.1


In my app I use Facebook Login. During login I ask only for read permissions as Facebook suggests. When I want to create a User Post, I have to obtain the publish_actions permission. Should I use the com.facebook.login.widget.LoginButton with setPublishPermissions("publish_actions") to relogin and get the permission and the new token?

I have checked the Facebook Developer documentation but I have not found something similar.

Thank you in advance


Solution

  • If you have your user already logged in, then wherever you want the permission to create a new post, you can just use the logInWithPublishPermissions of the LoginManager and pass it the permissions array.

    If the user hasn't provided you the publish permission till now, facebook will prompt the user asking him that your app is asking for user's permission. Only the screen which asks for post permission will be shown to user, not any other extra screens.

    Whereas, if the user hasn't logged in to your application till now, then first, the login screen will be shown and after that the screen asking post permissions will be shown.

    You can also check if the current access token that you have of the user, already has the publish permission of not, by getPermissions() method of the AccessToken class.