Search in sources :

Example 11 with AccessToken

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

the class SettingsFragment method setUpCallbacks.

private void setUpCallbacks() {
    callbackManager = CallbackManager.Factory.create();
    LoginManager manager = LoginManager.getInstance();
    manager.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Profile.fetchProfileForCurrentAccessToken();
        }

        @Override
        public void onError(FacebookException exception) {
            AccessToken.setCurrentAccessToken(null);
            currentUserChanged();
        }

        @Override
        public void onCancel() {
            AccessToken.setCurrentAccessToken(null);
            currentUserChanged();
        }
    });
    profileTracker = new ProfileTracker() {

        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
            Slot currentSlot = slotManager.getSelectedSlot();
            AccessToken currentAccessToken = AccessToken.getCurrentAccessToken();
            if (currentSlot != null && currentAccessToken != null && currentProfile != null) {
                currentSlot.setUserInfo(new UserInfo(currentProfile.getName(), currentAccessToken));
                currentUserChanged();
            }
        }
    };
}
Also used : LoginManager(com.facebook.login.LoginManager) ProfileTracker(com.facebook.ProfileTracker) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken) LoginResult(com.facebook.login.LoginResult) Profile(com.facebook.Profile)

Example 12 with AccessToken

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

the class FriendPickerFragment method createRequest.

private GraphRequest createRequest(String userID, Set<String> extraFields) {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    GraphRequest request = GraphRequest.newGraphPathRequest(accessToken, userID + friendPickerType.getRequestPath(), null);
    Set<String> fields = new HashSet<String>(extraFields);
    String[] requiredFields = new String[] { ID, NAME };
    fields.addAll(Arrays.asList(requiredFields));
    String pictureField = adapter.getPictureFieldSpecifier();
    if (pictureField != null) {
        fields.add(pictureField);
    }
    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);
    return request;
}
Also used : GraphRequest(com.facebook.GraphRequest) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle)

Example 13 with AccessToken

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

the class LoginClientTests method testReauthorizationWithSameFbidSucceeds.

@LargeTest
public void testReauthorizationWithSameFbidSucceeds() throws Exception {
    TestBlocker blocker = getTestBlocker();
    MockValidatingLoginClient client = new MockValidatingLoginClient(null, blocker);
    client.addAccessTokenToFbidMapping(USER_1_ACCESS_TOKEN, USER_1_FBID);
    client.addAccessTokenToFbidMapping(USER_2_ACCESS_TOKEN, USER_2_FBID);
    client.setPermissionsToReport(PERMISSIONS);
    LoginClient.Request request = createNewPermissionRequest();
    client.setRequest(request);
    AccessToken token = new AccessToken(USER_1_ACCESS_TOKEN, APP_ID, USER_1_FBID, PERMISSIONS, null, null, null, null);
    AccessToken.setCurrentAccessToken(token);
    LoginClient.Result result = LoginClient.Result.createTokenResult(request, token);
    client.completeAndValidate(result);
    blocker.waitForSignals(1);
    assertNotNull(client.result);
    assertEquals(LoginClient.Result.Code.SUCCESS, client.result.code);
    AccessToken resultToken = client.result.token;
    assertNotNull(resultToken);
    assertEquals(USER_1_ACCESS_TOKEN, resultToken.getToken());
    // We don't care about ordering.
    assertEquals(new HashSet<String>(PERMISSIONS), new HashSet<String>(resultToken.getPermissions()));
}
Also used : TestBlocker(com.facebook.TestBlocker) AccessToken(com.facebook.AccessToken) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 14 with AccessToken

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

the class LoginClientTests method testReauthorizationWithDifferentFbidsFails.

@LargeTest
public void testReauthorizationWithDifferentFbidsFails() throws Exception {
    TestBlocker blocker = getTestBlocker();
    MockValidatingLoginClient client = new MockValidatingLoginClient(null, blocker);
    client.addAccessTokenToFbidMapping(USER_1_ACCESS_TOKEN, USER_1_FBID);
    client.addAccessTokenToFbidMapping(USER_2_ACCESS_TOKEN, USER_2_FBID);
    client.setPermissionsToReport(PERMISSIONS);
    LoginClient.Request request = createNewPermissionRequest();
    client.setRequest(request);
    AccessToken userOneToken = new AccessToken(USER_1_ACCESS_TOKEN, APP_ID, USER_1_FBID, PERMISSIONS, null, null, null, null);
    AccessToken.setCurrentAccessToken(userOneToken);
    AccessToken userTwoToken = new AccessToken(USER_2_ACCESS_TOKEN, APP_ID, USER_2_FBID, PERMISSIONS, null, null, null, null);
    LoginClient.Result result = LoginClient.Result.createTokenResult(request, userTwoToken);
    client.completeAndValidate(result);
    blocker.waitForSignals(1);
    assertNotNull(client.result);
    assertEquals(LoginClient.Result.Code.ERROR, client.result.code);
    assertNull(client.result.token);
    assertNotNull(client.result.errorMessage);
}
Also used : TestBlocker(com.facebook.TestBlocker) AccessToken(com.facebook.AccessToken) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 15 with AccessToken

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

the class LoginResultTest method testInitialLogin.

@Test
public void testInitialLogin() {
    LoginClient.Request request = createRequest(EMAIL_SET, false);
    AccessToken accessToken = createAccessToken(PROFILE_EMAIL_SET, new HashSet<String>());
    LoginResult result = LoginManager.computeLoginResult(request, accessToken);
    assertEquals(accessToken, result.getAccessToken());
    assertEquals(PROFILE_EMAIL_SET, result.getRecentlyGrantedPermissions());
    assertEquals(0, result.getRecentlyDeniedPermissions().size());
}
Also used : AccessToken(com.facebook.AccessToken) Test(org.junit.Test)

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