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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations