Search in sources :

Example 16 with GraphResponse

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

the class Utility method getGraphMeRequestWithCacheAsync.

public static void getGraphMeRequestWithCacheAsync(final String accessToken, final GraphMeRequestWithCacheCallback callback) {
    JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
    if (cachedValue != null) {
        callback.onSuccess(cachedValue);
        return;
    }
    GraphRequest.Callback graphCallback = new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            if (response.getError() != null) {
                callback.onFailure(response.getError().getException());
            } else {
                ProfileInformationCache.putProfileInformation(accessToken, response.getJSONObject());
                callback.onSuccess(response.getJSONObject());
            }
        }
    };
    GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
    graphRequest.setCallback(graphCallback);
    graphRequest.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse)

Example 17 with GraphResponse

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

the class Utility method awaitGetGraphMeRequestWithCache.

public static JSONObject awaitGetGraphMeRequestWithCache(final String accessToken) {
    JSONObject cachedValue = ProfileInformationCache.getProfileInformation(accessToken);
    if (cachedValue != null) {
        return cachedValue;
    }
    GraphRequest graphRequest = getGraphMeRequestWithCache(accessToken);
    GraphResponse response = graphRequest.executeAndWait();
    if (response.getError() != null) {
        return null;
    }
    return response.getJSONObject();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse)

Example 18 with GraphResponse

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

the class UpdateUserPropertiesTests method testUserUpdateProperties.

public void testUserUpdateProperties() throws Exception {
    final TestBlocker blocker = getTestBlocker();
    Bundle parameters = new Bundle();
    parameters.putString("custom_value", "1");
    AppEventsLogger.setUserID("1");
    AppEventsLogger.updateUserProperties(parameters, getApplicationId(), new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            if (response.getError() != null) {
                blocker.setException(response.getError().getException());
            }
            blocker.signal();
        }
    });
    blocker.waitForSignals(1);
    if (blocker.getException() != null) {
        throw blocker.getException();
    }
}
Also used : TestBlocker(com.facebook.TestBlocker) GraphRequest(com.facebook.GraphRequest) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle)

Example 19 with GraphResponse

use of com.facebook.GraphResponse 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)

Aggregations

GraphRequest (com.facebook.GraphRequest)19 GraphResponse (com.facebook.GraphResponse)19 JSONObject (org.json.JSONObject)16 Bundle (android.os.Bundle)15 JSONException (org.json.JSONException)11 FacebookException (com.facebook.FacebookException)8 FacebookCallback (com.facebook.FacebookCallback)6 FacebookRequestError (com.facebook.FacebookRequestError)6 AccessToken (com.facebook.AccessToken)4 Uri (android.net.Uri)3 Bitmap (android.graphics.Bitmap)2 FacebookGraphResponseException (com.facebook.FacebookGraphResponseException)2 CollectionMapper (com.facebook.internal.CollectionMapper)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Intent (android.content.Intent)1 View (android.view.View)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 AppLink (bolts.AppLink)1