Search in sources :

Example 41 with GraphRequest

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

the class PostsRequest method makePublishPostRequest.

public static void makePublishPostRequest(String message, GraphRequest.Callback callback) {
    Bundle params = new Bundle();
    params.putString("message", message);
    GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), FEED_ENDPOINT, params, HttpMethod.POST, callback);
    request.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle)

Example 42 with GraphRequest

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

the class Utility method getGraphMeRequestWithCache.

private static GraphRequest getGraphMeRequestWithCache(final String accessToken) {
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,first_name,middle_name,last_name,link");
    parameters.putString("access_token", accessToken);
    GraphRequest graphRequest = new GraphRequest(null, "me", parameters, HttpMethod.GET, null);
    return graphRequest;
}
Also used : GraphRequest(com.facebook.GraphRequest) Bundle(android.os.Bundle)

Example 43 with GraphRequest

use of com.facebook.GraphRequest 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 44 with GraphRequest

use of com.facebook.GraphRequest 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 45 with GraphRequest

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

the class AppEventQueue method sendEventsToServer.

private static FlushStatistics sendEventsToServer(FlushReason reason, AppEventCollection appEventCollection) {
    FlushStatistics flushResults = new FlushStatistics();
    Context context = FacebookSdk.getApplicationContext();
    boolean limitEventUsage = FacebookSdk.getLimitEventAndDataUsage(context);
    List<GraphRequest> requestsToExecute = new ArrayList<>();
    for (AccessTokenAppIdPair accessTokenAppId : appEventCollection.keySet()) {
        GraphRequest request = buildRequestForSession(accessTokenAppId, appEventCollection.get(accessTokenAppId), limitEventUsage, flushResults);
        if (request != null) {
            requestsToExecute.add(request);
        }
    }
    if (requestsToExecute.size() > 0) {
        Logger.log(LoggingBehavior.APP_EVENTS, TAG, "Flushing %d events due to %s.", flushResults.numEvents, reason.toString());
        for (GraphRequest request : requestsToExecute) {
            // Execute the request synchronously. Callbacks will take care of handling errors
            // and updating our final overall result.
            request.executeAndWait();
        }
        return flushResults;
    }
    return null;
}
Also used : Context(android.content.Context) GraphRequest(com.facebook.GraphRequest) ArrayList(java.util.ArrayList)

Aggregations

GraphRequest (com.facebook.GraphRequest)52 Bundle (android.os.Bundle)39 GraphResponse (com.facebook.GraphResponse)25 JSONObject (org.json.JSONObject)22 FacebookException (com.facebook.FacebookException)15 JSONException (org.json.JSONException)15 FacebookRequestError (com.facebook.FacebookRequestError)8 AccessToken (com.facebook.AccessToken)7 FacebookCallback (com.facebook.FacebookCallback)5 Uri (android.net.Uri)4 JSONArray (org.json.JSONArray)4 Test (org.junit.Test)3 Intent (android.content.Intent)2 Location (android.location.Location)2 GraphRequestBatch (com.facebook.GraphRequestBatch)2 Profile (com.facebook.Profile)2 CollectionMapper (com.facebook.internal.CollectionMapper)2 CurrentPlaceFeedbackRequestParams (com.facebook.places.model.CurrentPlaceFeedbackRequestParams)2 PlaceInfoRequestParams (com.facebook.places.model.PlaceInfoRequestParams)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2