public static FetchedAppSettings queryAppSettings(final String applicationId, final boolean forceRequery) { // Cache the last app checked results. if (!forceRequery && fetchedAppSettings.containsKey(applicationId)) { return fetchedAppSettings.get(applicationId); } Bundle appSettingsParams = new Bundle(); appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS)); Request request = Request.newGraphPathRequest(null, applicationId, null); request.setParameters(appSettingsParams); GraphObject supportResponse = request.executeAndWait().getGraphObject(); FetchedAppSettings result = new FetchedAppSettings( safeGetBooleanFromResponse(supportResponse, SUPPORTS_ATTRIBUTION), safeGetBooleanFromResponse(supportResponse, SUPPORTS_IMPLICIT_SDK_LOGGING), safeGetStringFromResponse(supportResponse, NUX_CONTENT), safeGetBooleanFromResponse(supportResponse, NUX_ENABLED) ); fetchedAppSettings.put(applicationId, result); return result; }
public static void setAppEventAttributionParameters(GraphObject params, AttributionIdentifiers attributionIdentifiers, String hashedDeviceAndAppId, boolean limitEventUsage) { // Send attributionID if it exists, otherwise send a hashed device+appid specific value as the advertiser_id. if (attributionIdentifiers != null && attributionIdentifiers.getAttributionId() != null) { params.setProperty("attribution", attributionIdentifiers.getAttributionId()); } if (attributionIdentifiers != null && attributionIdentifiers.getAndroidAdvertiserId() != null) { params.setProperty("advertiser_id", attributionIdentifiers.getAndroidAdvertiserId()); params.setProperty("advertiser_tracking_enabled", !attributionIdentifiers.isTrackingLimited()); } else if (hashedDeviceAndAppId != null) { params.setProperty("advertiser_id", hashedDeviceAndAppId); } params.setProperty("application_tracking_enabled", !limitEventUsage); }
protected URI getPictureUriOfGraphObject(T graphObject) { String uri = null; Object o = graphObject.getProperty(PICTURE); if (o instanceof String) { uri = (String) o; } else if (o instanceof JSONObject) { ItemPicture itemPicture = GraphObject.Factory.create((JSONObject) o).cast(ItemPicture.class); ItemPictureData data = itemPicture.getData(); if (data != null) { uri = data.getUrl(); } } if (uri != null) { try { return new URI(uri); } catch (URISyntaxException e) { } } return null; }
private static int compareGraphObjects(GraphObject a, GraphObject b, Collection<String> sortFields, Collator collator) { for (String sortField : sortFields) { String sa = (String) a.getProperty(sortField); String sb = (String) b.getProperty(sortField); if (sa != null && sb != null) { int result = collator.compare(sa, sb); if (result != 0) { return result; } } else if (!(sa == null && sb == null)) { return (sa == null) ? -1 : 1; } } return 0; }
public static FetchedAppSettings queryAppSettings(final String applicationId, final boolean forceRequery) { // Cache the last app checked results. if (!forceRequery && fetchedAppSettings.containsKey(applicationId)) { return fetchedAppSettings.get(applicationId); } Bundle appSettingsParams = new Bundle(); appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS)); Request request = Request.newGraphPathRequest(null, applicationId, null); request.setParameters(appSettingsParams); GraphObject supportResponse = request.executeAndWait().getGraphObject(); FetchedAppSettings result = new FetchedAppSettings( safeGetBooleanFromResponse(supportResponse, SUPPORTS_ATTRIBUTION), safeGetBooleanFromResponse(supportResponse, SUPPORTS_IMPLICIT_SDK_LOGGING)); fetchedAppSettings.put(applicationId, result); return result; }
private void deleteTestAccount(String testAccountId, String appAccessToken) { Bundle parameters = new Bundle(); parameters.putString("access_token", appAccessToken); Request request = new Request(null, testAccountId, parameters, HttpMethod.DELETE); Response response = request.executeAndWait(); FacebookRequestError error = response.getError(); GraphObject graphObject = response.getGraphObject(); if (error != null) { Log.w(LOG_TAG, String.format("Could not delete test account %s: %s", testAccountId, error.getException().toString())); } else if (graphObject.getProperty(Response.NON_JSON_RESPONSE_PROPERTY) == (Boolean) false || graphObject.getProperty(Response.SUCCESS_KEY) == (Boolean) false) { Log.w(LOG_TAG, String.format("Could not delete test account %s: unknown reason", testAccountId)); } }
public static void setAppEventAttributionParameters( GraphObject params, AttributionIdentifiers attributionIdentifiers, String anonymousAppDeviceGUID, boolean limitEventUsage) { if (attributionIdentifiers != null && attributionIdentifiers.getAttributionId() != null) { params.setProperty("attribution", attributionIdentifiers.getAttributionId()); } if (attributionIdentifiers != null && attributionIdentifiers.getAndroidAdvertiserId() != null) { params.setProperty("advertiser_id", attributionIdentifiers.getAndroidAdvertiserId()); params.setProperty("advertiser_tracking_enabled", !attributionIdentifiers.isTrackingLimited()); } params.setProperty("anon_id", anonymousAppDeviceGUID); params.setProperty("application_tracking_enabled", !limitEventUsage); }
public static void setAppEventExtendedDeviceInfoParameters(GraphObject params, Context appContext) { JSONArray extraInfoArray = new JSONArray(); extraInfoArray.put(EXTRA_APP_EVENTS_INFO_FORMAT_VERSION); // Application Manifest info: String pkgName = appContext.getPackageName(); int versionCode = -1; String versionName = ""; try { PackageInfo pi = appContext.getPackageManager().getPackageInfo(pkgName, 0); versionCode = pi.versionCode; versionName = pi.versionName; } catch (PackageManager.NameNotFoundException e) { // Swallow } // Application Manifest info: extraInfoArray.put(pkgName); extraInfoArray.put(versionCode); extraInfoArray.put(versionName); params.setProperty("extinfo", extraInfoArray.toString()); }
private void showPublishResult(String message, GraphObject result, FacebookRequestError error) { String title = null; String alertMessage = null; if (error == null) { title = getString(R.string.success); alertMessage = getString(R.string.successfully_posted_post, message); } else { title = getString(R.string.error); alertMessage = error.getErrorMessage(); } new AlertDialog.Builder(this) .setTitle(title) .setMessage(alertMessage) .setPositiveButton(R.string.ok, null) .show(); }
private void deleteTestAccount(String testAccountId, String appAccessToken) { Bundle parameters = new Bundle(); parameters.putString("access_token", appAccessToken); Request request = new Request(null, testAccountId, parameters, HttpMethod.DELETE); Response response = request.executeAndWait(); FacebookRequestError error = response.getError(); GraphObject graphObject = response.getGraphObject(); if (error != null) { Log.w(LOG_TAG, String.format("Could not delete test account %s: %s", testAccountId, error.getException().toString())); } else if (graphObject.getProperty(Response.NON_JSON_RESPONSE_PROPERTY) == (Boolean) false) { Log.w(LOG_TAG, String.format("Could not delete test account %s: unknown reason", testAccountId)); } }
Response(Request request, HttpURLConnection connection, String rawResponse, GraphObject graphObject, GraphObjectList<GraphObject> graphObjects, boolean isFromCache, FacebookRequestError error) { this.request = request; this.connection = connection; this.rawResponse = rawResponse; this.graphObject = graphObject; this.graphObjectList = graphObjects; this.isFromCache = isFromCache; this.error = error; }
/** * The single graph object returned for this request, if any, cast into a particular type of GraphObject. * * @param graphObjectClass the GraphObject-derived interface to cast the graph object into * @return the graph object returned, or null if none was returned (or if the result was a list) * @throws FacebookException If the passed in Class is not a valid GraphObject interface */ public final <T extends GraphObject> T getGraphObjectAs(Class<T> graphObjectClass) { if (graphObject == null) { return null; } if (graphObjectClass == null) { throw new NullPointerException("Must pass in a valid interface that extends GraphObject"); } return graphObject.cast(graphObjectClass); }
private static Response createResponseFromObject(Request request, HttpURLConnection connection, Object object, boolean isFromCache, Object originalResult) throws JSONException { if (object instanceof JSONObject) { JSONObject jsonObject = (JSONObject) object; FacebookRequestError error = FacebookRequestError.checkResponseAndCreateError(jsonObject, originalResult, connection); if (error != null) { if (error.getErrorCode() == INVALID_SESSION_FACEBOOK_ERROR_CODE) { Session session = request.getSession(); if (session != null) { session.closeAndClearTokenInformation(); } } return new Response(request, connection, error); } Object body = Utility.getStringPropertyAsJSON(jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY); if (body instanceof JSONObject) { GraphObject graphObject = GraphObject.Factory.create((JSONObject) body); return new Response(request, connection, body.toString(), graphObject, isFromCache); } else if (body instanceof JSONArray) { GraphObjectList<GraphObject> graphObjectList = GraphObject.Factory.createList( (JSONArray) body, GraphObject.class); return new Response(request, connection, body.toString(), graphObjectList, isFromCache); } // We didn't get a body we understand how to handle, so pretend we got nothing. object = JSONObject.NULL; } if (object == JSONObject.NULL) { return new Response(request, connection, object.toString(), (GraphObject)null, isFromCache); } else { throw new FacebookException("Got unexpected object type in response, class: " + object.getClass().getSimpleName()); } }
private static boolean safeGetBooleanFromResponse(GraphObject response, String propertyName) { Object result = false; if (response != null) { result = response.getProperty(propertyName); } if (!(result instanceof Boolean)) { result = false; } return (Boolean) result; }
private static String safeGetStringFromResponse(GraphObject response, String propertyName) { Object result = ""; if (response != null) { result = response.getProperty(propertyName); } if (!(result instanceof String)) { result = ""; } return (String) result; }
int getPosition(String sectionKey, T graphObject) { int position = 0; boolean found = false; // First find the section key and increment position one for each header we will render; // increment by the size of each section prior to the one we want. for (String key : sectionKeys) { if (displaySections) { position++; } if (key.equals(sectionKey)) { found = true; break; } else { position += graphObjectsBySection.get(key).size(); } } if (!found) { return -1; } else if (graphObject == null) { // null represents the header for a section; we counted this header in position earlier, // so subtract it back out. return position - (displaySections ? 1 : 0); } // Now find index of this item within that section. for (T t : graphObjectsBySection.get(sectionKey)) { if (GraphObject.Factory.hasSameId(t, graphObject)) { return position; } position++; } return -1; }
public static Promise<GraphObject, BError, Void> getUserDetails(){ final Deferred<GraphObject, BError, Void> deferred = new DeferredObject<>(); if (Session.getActiveSession().getState().isOpened()) { // Request user data and show the results Request.newMeRequest(Session.getActiveSession(), new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (response != null) { try { deferred.resolve(user); } catch (Exception e) { deferred.reject(BError.getExceptionError(e)); } } } }).executeAsync(); } else deferred.reject(new BError(BError.Code.SESSION_CLOSED)); return deferred.promise(); }