Search in sources :

Example 6 with GraphUser

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);
}
Also used : GraphUser(com.facebook.model.GraphUser)

Example 7 with GraphUser

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);
            }
        }
    }
}
Also used : Response(com.facebook.Response) GraphUser(com.facebook.model.GraphUser) Request(com.facebook.Request) Session(com.facebook.Session)

Example 8 with GraphUser

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);
}
Also used : GraphUser(com.facebook.model.GraphUser)

Example 9 with GraphUser

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;
}
Also used : GraphUser(com.facebook.model.GraphUser) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 10 with GraphUser

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;
    }
}
Also used : ImageResponse(com.facebook.internal.ImageResponse) GraphUser(com.facebook.model.GraphUser) Bundle(android.os.Bundle) ImageRequest(com.facebook.internal.ImageRequest)

Aggregations

GraphUser (com.facebook.model.GraphUser)22 Bundle (android.os.Bundle)5 Response (com.facebook.Response)5 Session (com.facebook.Session)5 JSONException (org.json.JSONException)5 ActivityNotFoundException (android.content.ActivityNotFoundException)4 Request (com.facebook.Request)4 ImageRequest (com.facebook.internal.ImageRequest)4 ImageResponse (com.facebook.internal.ImageResponse)4 ArrayList (java.util.ArrayList)4 GraphUserCallback (com.facebook.Request.GraphUserCallback)3 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)3 GraphObject (com.facebook.model.GraphObject)3 FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)2 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)2 FacebookRequestError (com.facebook.FacebookRequestError)2 GraphMultiResult (com.facebook.model.GraphMultiResult)2 GraphObjectList (com.facebook.model.GraphObjectList)2 Random (java.util.Random)2 View (android.view.View)1