简体   繁体   中英

Facebook sdk Java - adding extended permissions with LoginButton

My app works well, but I also would like to list the pages I admin in Facebook. I add the manage_pages permission, to the login, and then I want to list the pages.

It works well on the Facebook Graph API Exlorer-

 SELECT manage_pages FROM permissions WHERE uid = me() 

I got manage_pages=1 . Then I listed my pages-

 SELECT page_id FROM page_admin WHERE uid =me()

I get all the page ids I admin.

But in my app I tried to add the manage_pages permission, and when I check the permissions in the app I get manage_pages=0

Here are a few line of my code:

LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("manage_pages"));
String fqlQuery = "SELECT manage_pages FROM permissions WHERE uid = me()";
Log.d("LINK_RESULT", (String) object.get("manage_pages"));

I get manage_pages=0 , but when I change it to "email", I get email=1

How do I add the extended permissions to the LoginButton?

See the section Request publish permissions in this link . It says that manage_pages is a publish permission. Its not a read permission!

Another thing- With the new SDKs, you need to separate the read and the write permissions. You can first open session for read, get what you want and then open for publish. According to the facebook documentation -

If any publish permissions are included, the login attempt by the user will fail. 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.

You need to call clearPermissions() in between the two calls. Hope it helps. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM