Note that there are some explanatory texts on larger screens.

plurals
  1. POStatusCallback not called after requestNewReadPermissions then requestNewPublishPermissions
    primarykey
    data
    text
    <p>I am developing an Android App that integrates with Facebook. I would like to:</p> <ol> <li>Let the user login with Facebook</li> <li>Get the user's email address on Facebook (could be a <a href="https://developers.facebook.com/blog/post/355/">proxied email address</a>, which is fine)</li> <li>Post to the user's wall/timeline on his/her behalf</li> </ol> <p>Technically, that would be to:</p> <ol> <li>Authenticate the user</li> <li>Request the <a href="http://developers.facebook.com/docs/reference/login/email-permissions/"><code>email</code> permission</a></li> <li>Request the <a href="http://developers.facebook.com/docs/reference/login/extended-permissions/"><code>publish_stream</code> permission</a></li> </ol> <h3>1. Authenticate the user</h3> <p>I called <a href="http://developers.facebook.com/docs/reference/android/3.0/Session#openActiveSession%28Activity,%20boolean,%20StatusCallback%29"><code>Session.openActiveSession()</code></a> with a <a href="http://developers.facebook.com/docs/reference/android/3.0/Session.StatusCallback"><code>Session.StatusCallback</code></a> (I already checked that there is no active opened session beforehand):</p> <pre><code>final Session.StatusCallback sessionStatusCallback = new Session.StatusCallback() { public void call(final Session session, SessionState state, Exception exception) { // If there is an exception... if(exception != null) { // Handle fail case here. return; } // If session is just opened... if(state == SessionState.OPENED) { // Handle success case here. return; } }; }; // Start Facebook Login. Session.openActiveSession(activity, true, sessionStatusCallback); </code></pre> <p>My callback is called after successful login. So far so good.</p> <h3>2. Request the <a href="http://developers.facebook.com/docs/reference/login/email-permissions/"><code>email</code> permission</a></h3> <p>This is my status callback:</p> <pre><code>new Session.StatusCallback() { public void call(final Session session, SessionState state, Exception exception) { // If there is an exception... if(exception != null) { // Handle fail case here. return; } // If token is just updated... if(state == SessionState.OPENED_TOKEN_UPDATED) { // Handle success case here. return; } }; }; </code></pre> <p>I request the permission with <a href="http://developers.facebook.com/docs/reference/android/3.0/Session#requestNewReadPermissions%28NewPermissionsRequest%29"><code>Session.requestNewReadPermissions()</code></a>:</p> <pre><code>final Session session = Session.getActiveSession(); final static String[] PERMISSION_ARRAY_READ = {"email"}; final List&lt;String&gt; permissionList = Arrays.asList(PERMISSION_ARRAY_READ); // If all required permissions are available... if(session.getPermissions().containsAll(permissionList)) { // Handle success case here. return; } // Request permissions. session.requestNewReadPermissions(new Session.NewPermissionsRequest(activity, permissionList)); </code></pre> <p>My callback is called after permission is granted. So far so good.</p> <h3>3. Request the <a href="http://developers.facebook.com/docs/reference/login/extended-permissions/"><code>publish_stream</code> permission</a></h3> <p>This is my status callback:</p> <pre><code>new Session.StatusCallback() { public void call(final Session session, SessionState state, Exception exception) { // If there is an exception... if(exception != null) { // Handle fail case here. return; } // If token is just updated... if(state == SessionState.OPENED_TOKEN_UPDATED) { // Handle success case here. return; } }; }; </code></pre> <p>I request the permission with <a href="http://developers.facebook.com/docs/reference/android/3.0/Session#requestNewPublishPermissions%28NewPermissionsRequest%29"><code>Session.requestNewPublishPermissions()</code></a>:</p> <pre><code>final Session session = Session.getActiveSession(); final static String[] PERMISSION_ARRAY_PUBLISH = {"publish_stream"}; final List&lt;String&gt; permissionList = Arrays.asList(PERMISSION_ARRAY_PUBLISH); // If all required permissions are available... if(session.getPermissions().containsAll(permissionList)) { // Handle success case here. return; } // Request permissions. session.requestNewPublishPermissions(new Session.NewPermissionsRequest(activity, permissionList)); </code></pre> <p>This time, my callback is <strong>not</strong> called after permission is granted.</p> <h3>Investigation</h3> <p>Upon further investigation, I found that my callback is triggered by <a href="https://github.com/facebook/facebook-android-sdk/blob/sdk-version-3.0/facebook/src/com/facebook/Session.java#L1160-1164"><code>com.facebook.Session#postStateChange(SessionState, SessionState, Exception)</code></a>:</p> <pre><code>void postStateChange(final SessionState oldState, final SessionState newState, final Exception exception) { if (oldState == newState &amp;&amp; exception == null) { return; } /* ... */ } </code></pre> <p>Since <code>oldState</code> and <code>newState</code> are equal (both being <a href="http://developers.facebook.com/docs/reference/android/3.0/SessionState#OPENED_TOKEN_UPDATED"><code>SessionState.OPENED_TOKEN_UPDATED</code></a>, my callback is not called.</p> <h3>Question</h3> <p>How can I receive any notification after permission is granted for the 2nd time? Am I supposed to <a href="http://developers.facebook.com/docs/reference/android/3.0/Session#close%28%29"><code>close()</code></a> the session and <a href="http://developers.facebook.com/docs/reference/android/3.0/Session#openActiveSessionFromCache%28Context%29">re-open it from cache</a>?</p> <h3>Additional info</h3> <p>My Facebook Android SDK 3.0 is download from <a href="https://developers.facebook.com/resources/facebook-android-sdk-3.0.zip">here</a>, which is stated in Facebook's <a href="http://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/">Getting Started with the Facebook SDK for Android</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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