Search in sources :

Example 6 with GraphRequest

use of com.facebook.GraphRequest 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;
}
Also used : GraphRequest(com.facebook.GraphRequest) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle)

Example 7 with GraphRequest

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

the class AppEventQueue method buildRequestForSession.

private static GraphRequest buildRequestForSession(final AccessTokenAppIdPair accessTokenAppId, final SessionEventsState appEvents, final boolean limitEventUsage, final FlushStatistics flushState) {
    String applicationId = accessTokenAppId.getApplicationId();
    FetchedAppSettings fetchedAppSettings = FetchedAppSettingsManager.queryAppSettings(applicationId, false);
    final GraphRequest postRequest = GraphRequest.newPostRequest(null, String.format("%s/activities", applicationId), null, null);
    Bundle requestParameters = postRequest.getParameters();
    if (requestParameters == null) {
        requestParameters = new Bundle();
    }
    requestParameters.putString("access_token", accessTokenAppId.getAccessTokenString());
    String pushNotificationsRegistrationId = AppEventsLogger.getPushNotificationsRegistrationId();
    if (pushNotificationsRegistrationId != null) {
        requestParameters.putString("device_token", pushNotificationsRegistrationId);
    }
    postRequest.setParameters(requestParameters);
    boolean supportsImplicitLogging = false;
    if (fetchedAppSettings != null) {
        supportsImplicitLogging = fetchedAppSettings.supportsImplicitLogging();
    }
    int numEvents = appEvents.populateRequest(postRequest, FacebookSdk.getApplicationContext(), supportsImplicitLogging, limitEventUsage);
    if (numEvents == 0) {
        return null;
    }
    flushState.numEvents += numEvents;
    postRequest.setCallback(new GraphRequest.Callback() {

        @Override
        public void onCompleted(GraphResponse response) {
            handleResponse(accessTokenAppId, postRequest, response, appEvents, flushState);
        }
    });
    return postRequest;
}
Also used : FetchedAppSettings(com.facebook.internal.FetchedAppSettings) GraphRequest(com.facebook.GraphRequest) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle)

Example 8 with GraphRequest

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

the class AppLinkData method fetchDeferredAppLinkFromServer.

private static void fetchDeferredAppLinkFromServer(Context context, String applicationId, final CompletionHandler completionHandler) {
    JSONObject deferredApplinkParams = new JSONObject();
    try {
        deferredApplinkParams.put("event", DEFERRED_APP_LINK_EVENT);
        Utility.setAppEventAttributionParameters(deferredApplinkParams, AttributionIdentifiers.getAttributionIdentifiers(context), AppEventsLogger.getAnonymousAppDeviceGUID(context), FacebookSdk.getLimitEventAndDataUsage(context));
        Utility.setAppEventExtendedDeviceInfoParameters(deferredApplinkParams, FacebookSdk.getApplicationContext());
        deferredApplinkParams.put("application_package_name", context.getPackageName());
    } catch (JSONException e) {
        throw new FacebookException("An error occurred while preparing deferred app link", e);
    }
    String deferredApplinkUrlPath = String.format(DEFERRED_APP_LINK_PATH, applicationId);
    AppLinkData appLinkData = null;
    try {
        GraphRequest deferredApplinkRequest = GraphRequest.newPostRequest(null, deferredApplinkUrlPath, deferredApplinkParams, null);
        GraphResponse deferredApplinkResponse = deferredApplinkRequest.executeAndWait();
        JSONObject jsonResponse = deferredApplinkResponse.getJSONObject();
        if (jsonResponse != null) {
            final String appLinkArgsJsonString = jsonResponse.optString(DEFERRED_APP_LINK_ARGS_FIELD);
            final long tapTimeUtc = jsonResponse.optLong(DEFERRED_APP_LINK_CLICK_TIME_FIELD, -1);
            final String appLinkClassName = jsonResponse.optString(DEFERRED_APP_LINK_CLASS_FIELD);
            final String appLinkUrl = jsonResponse.optString(DEFERRED_APP_LINK_URL_FIELD);
            if (!TextUtils.isEmpty(appLinkArgsJsonString)) {
                appLinkData = createFromJson(appLinkArgsJsonString);
                if (tapTimeUtc != -1) {
                    try {
                        if (appLinkData.arguments != null) {
                            appLinkData.arguments.put(ARGUMENTS_TAPTIME_KEY, tapTimeUtc);
                        }
                        if (appLinkData.argumentBundle != null) {
                            appLinkData.argumentBundle.putString(ARGUMENTS_TAPTIME_KEY, Long.toString(tapTimeUtc));
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
                    }
                }
                if (appLinkClassName != null) {
                    try {
                        if (appLinkData.arguments != null) {
                            appLinkData.arguments.put(ARGUMENTS_NATIVE_CLASS_KEY, appLinkClassName);
                        }
                        if (appLinkData.argumentBundle != null) {
                            appLinkData.argumentBundle.putString(ARGUMENTS_NATIVE_CLASS_KEY, appLinkClassName);
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
                    }
                }
                if (appLinkUrl != null) {
                    try {
                        if (appLinkData.arguments != null) {
                            appLinkData.arguments.put(ARGUMENTS_NATIVE_URL, appLinkUrl);
                        }
                        if (appLinkData.argumentBundle != null) {
                            appLinkData.argumentBundle.putString(ARGUMENTS_NATIVE_URL, appLinkUrl);
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "Unable to put tap time in AppLinkData.arguments");
                    }
                }
            }
        }
    } catch (Exception e) {
        Utility.logd(TAG, "Unable to fetch deferred applink from server");
    }
    completionHandler.onDeferredAppLinkDataFetched(appLinkData);
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException)

Example 9 with GraphRequest

use of com.facebook.GraphRequest in project react-native-fbsdk by facebook.

the class FBGraphRequestModule method buildRequest.

private GraphRequest buildRequest(ReadableMap requestMap) {
    GraphRequest graphRequest = new GraphRequest();
    graphRequest.setGraphPath(requestMap.getString("graphPath"));
    setConfig(graphRequest, requestMap.getMap("config"));
    return graphRequest;
}
Also used : GraphRequest(com.facebook.GraphRequest)

Example 10 with GraphRequest

use of com.facebook.GraphRequest in project react-native-fbsdk by facebook.

the class FBGraphRequestModule method start.

/**
     * Send the batch of requests.
     * @param requestBatch
     * @param timeout
     * @param batchCallback
     */
@ReactMethod
public void start(ReadableArray requestBatch, int timeout, Callback batchCallback) {
    GraphRequestBatch batch = new GraphRequestBatch();
    int potentialID = 0;
    int batchID = 0;
    synchronized (this) {
        do {
            batchID = potentialID++;
        } while (mResponses.get(batchID) != null);
        mResponses.put(batchID, Arguments.createMap());
    }
    for (int i = 0; i < requestBatch.size(); i++) {
        GraphRequest request = buildRequest(requestBatch.getMap(i));
        request.setCallback(new GraphRequestCallback(i, batchID));
        batch.add(request);
    }
    batch.setTimeout(timeout);
    GraphRequestBatchCallback callback = new GraphRequestBatchCallback(batchID, batchCallback);
    batch.addCallback(callback);
    batch.executeAsync();
}
Also used : GraphRequest(com.facebook.GraphRequest) GraphRequestBatch(com.facebook.GraphRequestBatch) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

GraphRequest (com.facebook.GraphRequest)29 Bundle (android.os.Bundle)22 GraphResponse (com.facebook.GraphResponse)17 JSONObject (org.json.JSONObject)16 JSONException (org.json.JSONException)12 FacebookException (com.facebook.FacebookException)9 AccessToken (com.facebook.AccessToken)5 FacebookCallback (com.facebook.FacebookCallback)5 FacebookRequestError (com.facebook.FacebookRequestError)5 Uri (android.net.Uri)3 CollectionMapper (com.facebook.internal.CollectionMapper)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 View (android.view.View)1 Button (android.widget.Button)1