use of com.facebook.model.GraphUser in project phonegap-facebook-plugin by Wizcorp.
the class FriendPickerFragment method setSelection.
/**
* Sets the list of friends for pre selection. These friends will be selected by default.
* @param graphUsers list of friends as GraphUsers
*/
public void setSelection(List<GraphUser> graphUsers) {
List<String> userIds = new ArrayList<String>();
for (GraphUser graphUser : graphUsers) {
userIds.add(graphUser.getId());
}
setSelectionByIds(userIds);
}
use of com.facebook.model.GraphUser in project Klyph by jonathangerbaud.
the class LoginButton method fetchUserInfo.
private void fetchUserInfo() {
if (fetchUserInfo) {
final Session currentSession = sessionTracker.getOpenSession();
if (currentSession != null) {
if (currentSession != userInfoSession) {
Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser me, Response response) {
if (currentSession == sessionTracker.getOpenSession()) {
user = me;
if (userInfoChangedCallback != null) {
userInfoChangedCallback.onUserInfoFetched(user);
}
}
if (response.getError() != null) {
handleError(response.getError().getException());
}
}
});
Request.executeBatchAsync(request);
userInfoSession = currentSession;
}
} else {
user = null;
if (userInfoChangedCallback != null) {
userInfoChangedCallback.onUserInfoFetched(user);
}
}
}
}
use of com.facebook.model.GraphUser in project facebook-api-android-maven by avianey.
the class FriendPickerFragment method setSelection.
/**
* Sets the list of friends for pre selection. These friends will be selected by default.
* @param graphUsers list of friends as GraphUsers
*/
public void setSelection(List<GraphUser> graphUsers) {
List<String> userIds = new ArrayList<String>();
for (GraphUser graphUser : graphUsers) {
userIds.add(graphUser.getId());
}
setSelectionByIds(userIds);
}
use of com.facebook.model.GraphUser in project facebook-api-android-maven by avianey.
the class AuthorizationClient method createReauthValidationBatch.
RequestBatch createReauthValidationBatch(final Result pendingResult) {
// We need to ensure that the token we got represents the same fbid as the old one. We issue
// a "me" request using the current token, a "me" request using the new token, and a "me/permissions"
// request using the current token to get the permissions of the user.
final ArrayList<String> fbids = new ArrayList<String>();
final ArrayList<String> grantedPermissions = new ArrayList<String>();
final ArrayList<String> declinedPermissions = new ArrayList<String>();
final String newToken = pendingResult.token.getToken();
Request.Callback meCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
GraphUser user = response.getGraphObjectAs(GraphUser.class);
if (user != null) {
fbids.add(user.getId());
}
} catch (Exception ex) {
}
}
};
String validateSameFbidAsToken = pendingRequest.getPreviousAccessToken();
Request requestCurrentTokenMe = createGetProfileIdRequest(validateSameFbidAsToken);
requestCurrentTokenMe.setCallback(meCallback);
Request requestNewTokenMe = createGetProfileIdRequest(newToken);
requestNewTokenMe.setCallback(meCallback);
Request requestCurrentTokenPermissions = createGetPermissionsRequest(validateSameFbidAsToken);
requestCurrentTokenPermissions.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
Session.PermissionsPair permissionsPair = Session.handlePermissionResponse(response);
if (permissionsPair != null) {
grantedPermissions.addAll(permissionsPair.getGrantedPermissions());
declinedPermissions.addAll(permissionsPair.getDeclinedPermissions());
}
} catch (Exception ex) {
}
}
});
RequestBatch batch = new RequestBatch(requestCurrentTokenMe, requestNewTokenMe, requestCurrentTokenPermissions);
batch.setBatchApplicationId(pendingRequest.getApplicationId());
batch.addCallback(new RequestBatch.Callback() {
@Override
public void onBatchCompleted(RequestBatch batch) {
try {
Result result = null;
if (fbids.size() == 2 && fbids.get(0) != null && fbids.get(1) != null && fbids.get(0).equals(fbids.get(1))) {
// Modify the token to have the right permission set.
AccessToken tokenWithPermissions = AccessToken.createFromTokenWithRefreshedPermissions(pendingResult.token, grantedPermissions, declinedPermissions);
result = Result.createTokenResult(pendingRequest, tokenWithPermissions);
} else {
result = Result.createErrorResult(pendingRequest, "User logged in as different Facebook user.", null);
}
complete(result);
} catch (Exception ex) {
complete(Result.createErrorResult(pendingRequest, "Caught exception", ex.getMessage()));
} finally {
notifyBackgroundProcessingStop();
}
}
});
return batch;
}
use of com.facebook.model.GraphUser in project facebook-api-android-maven by avianey.
the class UserSettingsFragment method fetchUserInfo.
private void fetchUserInfo() {
final Session currentSession = getSession();
if (currentSession != null && currentSession.isOpened()) {
if (currentSession != userInfoSession) {
Request request = Request.newMeRequest(currentSession, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser me, Response response) {
if (currentSession == getSession()) {
user = me;
updateUI();
}
if (response.getError() != null) {
loginButton.handleError(response.getError().getException());
}
}
});
Bundle parameters = new Bundle();
parameters.putString(FIELDS, REQUEST_FIELDS);
request.setParameters(parameters);
Request.executeBatchAsync(request);
userInfoSession = currentSession;
}
} else {
user = null;
}
}
Aggregations