Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to request permissions with Facebook's new Android SDK 3.0?
    primarykey
    data
    text
    <p>With Facebook's new Android SDK 3.0 (that was released a few days ago), the process of authentication has changed.</p> <p>So how do you request a read permission such as "friends_hometown"?</p> <p>The following code is how I am trying to do it - but I'm quite sure it's not the way you should do this:</p> <p><strong>Version 1:</strong></p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Session.openActiveSession(this, true, new Session.StatusCallback() { // start Facebook login @Override public void call(Session session, SessionState state, Exception exception) { // callback for session state changes if (session.isOpened()) { List&lt;String&gt; permissions = new ArrayList&lt;String&gt;(); permissions.add("friends_hometown"); session.requestNewReadPermissions(new Session.NewPermissionsRequest(FBImport.this, permissions)); Request.executeGraphPathRequestAsync(session, "me/friends/?access_token="+session.getAccessToken()+"&amp;fields=id,name,hometown", new Request.Callback() { ... }); } } }); } </code></pre> <p><strong>Version 2:</strong></p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Session currentSession = Session.getActiveSession(); if (currentSession == null || currentSession.getState().isClosed()) { Session session = Session.openActiveSession(this, true, fbStatusCallback); // PROBLEM: NO PERMISSIONS YET BUT CALLBACK IS EXECUTED ON OPEN currentSession = session; } if (currentSession != null &amp;&amp; !currentSession.isOpened()) { OpenRequest openRequest = new OpenRequest(this).setCallback(fbStatusCallback); // HERE IT IS OKAY TO EXECUTE THE CALLBACK BECAUSE WE'VE GOT THE PERMISSIONS if (openRequest != null) { openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS); openRequest.setPermissions(Arrays.asList("friends_hometown")); openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK); currentSession.openForRead(openRequest); } } } </code></pre> <p>What I'm doing is to request the permission as soon as the session is open - but at this point the code is already starting a Graph API request, thus the permission request comes to late ...</p> <p>Can't you request a permission at the same time you initialize the session?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload