Search in sources :

Example 46 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class UserSettingsFragment method fetchUserInfo.

private void fetchUserInfo() {
    final AccessToken accessToken = AccessToken.getCurrentAccessToken();
    if (accessToken != null) {
        GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {

            @Override
            public void onCompleted(JSONObject me, GraphResponse response) {
                user = me;
                updateUI();
            }
        });
        Bundle parameters = new Bundle();
        parameters.putString(FIELDS, REQUEST_FIELDS);
        request.setParameters(parameters);
        GraphRequest.executeBatchAsync(request);
    } else {
        user = null;
    }
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle)

Example 47 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class UserSettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    accessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            fetchUserInfo();
            updateUI();
        }
    };
    callbackManager = CallbackManager.Factory.create();
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) AccessToken(com.facebook.AccessToken)

Example 48 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class ProfileFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    callbackManager = CallbackManager.Factory.create();
    profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            setProfile(currentProfile);
        }
    };
    accessTokenTracker = new AccessTokenTracker() {

        @Override
        protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
            // On AccessToken changes fetch the new profile which fires the event on
            // the ProfileTracker if the profile is different
            Profile.fetchProfileForCurrentAccessToken();
        }
    };
    // Ensure that our profile is up to date
    Profile.fetchProfileForCurrentAccessToken();
    setProfile(Profile.getCurrentProfile());
}
Also used : AccessTokenTracker(com.facebook.AccessTokenTracker) ProfileTracker(com.facebook.ProfileTracker) AccessToken(com.facebook.AccessToken) Profile(com.facebook.Profile)

Example 49 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class SettingsFragment method currentUserChanged.

private void currentUserChanged() {
    if (slotManager == null) {
        // Fragment has not had onCreate called yet.
        return;
    }
    updateMenuVisibility();
    updateListView();
    Slot currentSlot = slotManager.getSelectedSlot();
    AccessToken currentToken = (currentSlot != null) ? currentSlot.getAccessToken() : null;
    AccessToken.setCurrentAccessToken(currentToken);
}
Also used : AccessToken(com.facebook.AccessToken)

Aggregations

AccessToken (com.facebook.AccessToken)49 Test (org.junit.Test)16 Bundle (android.os.Bundle)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Date (java.util.Date)9 Intent (android.content.Intent)8 AccessTokenTracker (com.facebook.AccessTokenTracker)7 FacebookException (com.facebook.FacebookException)7 GraphRequest (com.facebook.GraphRequest)5 GraphResponse (com.facebook.GraphResponse)4 JSONObject (org.json.JSONObject)4 JSONException (org.json.JSONException)3 IntentFilter (android.content.IntentFilter)2 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 Profile (com.facebook.Profile)2 ProfileTracker (com.facebook.ProfileTracker)2 TestBlocker (com.facebook.TestBlocker)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2