use of com.facebook.model.GraphObject in project Klyph by jonathangerbaud.
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));
fetchedAppSettings.put(applicationId, result);
return result;
}
use of com.facebook.model.GraphObject in project Klyph by jonathangerbaud.
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 Klyph by jonathangerbaud.
the class AuthorizationClient method createReauthValidationBatch.
RequestBatch createReauthValidationBatch(final Result pendingResult) {
// We need to ensure that the token we got represents the same fbid as the old one. We issue
// a "me" request using the current token, a "me" request using the new token, and a "me/permissions"
// request using the current token to get the permissions of the user.
final ArrayList<String> fbids = new ArrayList<String>();
final ArrayList<String> tokenPermissions = new ArrayList<String>();
final String newToken = pendingResult.token.getToken();
Request.Callback meCallback = new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
GraphUser user = response.getGraphObjectAs(GraphUser.class);
if (user != null) {
fbids.add(user.getId());
}
} catch (Exception ex) {
}
}
};
String validateSameFbidAsToken = pendingRequest.getPreviousAccessToken();
Request requestCurrentTokenMe = createGetProfileIdRequest(validateSameFbidAsToken);
requestCurrentTokenMe.setCallback(meCallback);
Request requestNewTokenMe = createGetProfileIdRequest(newToken);
requestNewTokenMe.setCallback(meCallback);
Request requestCurrentTokenPermissions = createGetPermissionsRequest(validateSameFbidAsToken);
requestCurrentTokenPermissions.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
try {
GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
if (result != null) {
GraphObjectList<GraphObject> data = result.getData();
if (data != null && data.size() == 1) {
GraphObject permissions = data.get(0);
// The keys are the permission names.
tokenPermissions.addAll(permissions.asMap().keySet());
}
}
} catch (Exception ex) {
}
}
});
RequestBatch batch = new RequestBatch(requestCurrentTokenMe, requestNewTokenMe, requestCurrentTokenPermissions);
batch.setBatchApplicationId(pendingRequest.getApplicationId());
batch.addCallback(new RequestBatch.Callback() {
@Override
public void onBatchCompleted(RequestBatch batch) {
try {
Result result = null;
if (fbids.size() == 2 && fbids.get(0) != null && fbids.get(1) != null && fbids.get(0).equals(fbids.get(1))) {
// Modify the token to have the right permission set.
AccessToken tokenWithPermissions = AccessToken.createFromTokenWithRefreshedPermissions(pendingResult.token, tokenPermissions);
result = Result.createTokenResult(pendingRequest, tokenWithPermissions);
} else {
result = Result.createErrorResult(pendingRequest, "User logged in as different Facebook user.", null);
}
complete(result);
} catch (Exception ex) {
complete(Result.createErrorResult(pendingRequest, "Caught exception", ex.getMessage()));
} finally {
notifyBackgroundProcessingStop();
}
}
});
return batch;
}
use of com.facebook.model.GraphObject in project Klyph by jonathangerbaud.
the class TestSession method deleteTestAccount.
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));
}
}
use of com.facebook.model.GraphObject in project Klyph by jonathangerbaud.
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