use of com.facebook.model.GraphObject in project phonegap-facebook-plugin by Wizcorp.
the class Utility method getStringPropertyAsJSON.
// Returns either a JSONObject or JSONArray representation of the 'key' property of 'jsonObject'.
public static Object getStringPropertyAsJSON(JSONObject jsonObject, String key, String nonJSONPropertyKey) throws JSONException {
Object value = jsonObject.opt(key);
if (value != null && value instanceof String) {
JSONTokener tokener = new JSONTokener((String) value);
value = tokener.nextValue();
}
if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) {
if (nonJSONPropertyKey != null) {
// Facebook sometimes gives us back a non-JSON value such as
// literal "true" or "false" as a result.
// If we got something like that, we present it to the caller as
// a GraphObject with a single
// property. We only do this if the caller wants that behavior.
jsonObject = new JSONObject();
jsonObject.putOpt(nonJSONPropertyKey, value);
return jsonObject;
} else {
throw new FacebookException("Got an unexpected non-JSON object.");
}
}
return value;
}
use of com.facebook.model.GraphObject in project phonegap-facebook-plugin by Wizcorp.
the class Utility method getAppSettingsQueryResponse.
// Note that this method makes a synchronous Graph API call, so should not be called from the main thread.
private static GraphObject getAppSettingsQueryResponse(String applicationId) {
Bundle appSettingsParams = new Bundle();
appSettingsParams.putString(APPLICATION_FIELDS, TextUtils.join(",", APP_SETTING_FIELDS));
Request request = Request.newGraphPathRequest(null, applicationId, null);
request.setSkipClientToken(true);
request.setParameters(appSettingsParams);
GraphObject response = request.executeAndWait().getGraphObject();
return response;
}
use of com.facebook.model.GraphObject in project Klyph by jonathangerbaud.
the class Settings method publishInstallAndWaitForResponse.
static Response publishInstallAndWaitForResponse(final Context context, final String applicationId, final boolean isAutoPublish) {
try {
if (context == null || applicationId == null) {
throw new IllegalArgumentException("Both context and applicationId must be non-null");
}
String attributionId = Settings.getAttributionId(context.getContentResolver());
SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES, Context.MODE_PRIVATE);
String pingKey = applicationId + "ping";
String jsonKey = applicationId + "json";
long lastPing = preferences.getLong(pingKey, 0);
String lastResponseJSON = preferences.getString(jsonKey, null);
// prevent auto publish from occurring if we have an explicit call.
if (!isAutoPublish) {
setShouldAutoPublishInstall(false);
}
GraphObject publishParams = GraphObject.Factory.create();
publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT);
Utility.setAppEventAttributionParameters(publishParams, attributionId, Utility.getHashedDeviceAndAppID(context, applicationId), !getLimitEventAndDataUsage(context));
publishParams.setProperty(AUTO_PUBLISH, isAutoPublish);
publishParams.setProperty("application_package_name", context.getPackageName());
String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId);
Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null);
if (lastPing != 0) {
GraphObject graphObject = null;
try {
if (lastResponseJSON != null) {
graphObject = GraphObject.Factory.create(new JSONObject(lastResponseJSON));
}
} catch (JSONException je) {
// return the default graph object if there is any problem reading the data.
}
if (graphObject == null) {
return Response.createResponsesFromString("true", null, new RequestBatch(publishRequest), true).get(0);
} else {
return new Response(null, null, graphObject, true);
}
} else if (attributionId == null) {
throw new FacebookException("No attribution id returned from the Facebook application");
} else {
if (!Utility.queryAppSettings(applicationId, false).supportsAttribution()) {
throw new FacebookException("Install attribution has been disabled on the server.");
}
Response publishResponse = publishRequest.executeAndWait();
// denote success since no error threw from the post.
SharedPreferences.Editor editor = preferences.edit();
lastPing = System.currentTimeMillis();
editor.putLong(pingKey, lastPing);
// if we got an object response back, cache the string of the JSON.
if (publishResponse.getGraphObject() != null && publishResponse.getGraphObject().getInnerJSONObject() != null) {
editor.putString(jsonKey, publishResponse.getGraphObject().getInnerJSONObject().toString());
}
editor.commit();
return publishResponse;
}
} catch (Exception e) {
// if there was an error, fall through to the failure case.
Utility.logd("Facebook-publish", e);
return new Response(null, null, new FacebookRequestError(null, e));
}
}
use of com.facebook.model.GraphObject in project facebook-api-android-maven by avianey.
the class Utility method queryAppSettings.
// Note that this method makes a synchronous Graph API call, so should not be called from the main thread.
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;
}
use of com.facebook.model.GraphObject in project facebook-api-android-maven by avianey.
the class GraphObjectAdapter method rebuildSections.
private void rebuildSections() {
sectionKeys = new ArrayList<String>();
graphObjectsBySection = new HashMap<String, ArrayList<T>>();
graphObjectsById = new HashMap<String, T>();
displaySections = false;
if (cursor == null || cursor.getCount() == 0) {
return;
}
int objectsAdded = 0;
cursor.moveToFirst();
do {
T graphObject = cursor.getGraphObject();
if (!filterIncludesItem(graphObject)) {
continue;
}
objectsAdded++;
String sectionKeyOfItem = getSectionKeyOfGraphObject(graphObject);
if (!graphObjectsBySection.containsKey(sectionKeyOfItem)) {
sectionKeys.add(sectionKeyOfItem);
graphObjectsBySection.put(sectionKeyOfItem, new ArrayList<T>());
}
List<T> section = graphObjectsBySection.get(sectionKeyOfItem);
section.add(graphObject);
graphObjectsById.put(getIdOfGraphObject(graphObject), graphObject);
} while (cursor.moveToNext());
if (sortFields != null) {
final Collator collator = Collator.getInstance();
for (List<T> section : graphObjectsBySection.values()) {
Collections.sort(section, new Comparator<GraphObject>() {
@Override
public int compare(GraphObject a, GraphObject b) {
return compareGraphObjects(a, b, sortFields, collator);
}
});
}
}
Collections.sort(sectionKeys, Collator.getInstance());
displaySections = sectionKeys.size() > 1 && objectsAdded > DISPLAY_SECTIONS_THRESHOLD;
}
Aggregations