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();
}
}
};
}
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;
}
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()));
}
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);
}
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());
}
Aggregations