Java Code Examples for com.facebook.model.GraphObject#getProperty()

The following examples show how to use com.facebook.model.GraphObject#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphObjectAdapter.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: GraphObjectAdapter.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: GraphObjectAdapter.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: GraphObjectAdapter.java    From HypFacebook with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 5
Source File: GraphObjectAdapter.java    From android-skeleton-project with MIT License 6 votes vote down vote up
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;
}
 
Example 6
Source File: Utility.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: GraphRequestTests.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
@LargeTest
public void testCommentRoundTrip() {
    TestSession session = openTestSessionWithSharedUser();

    GraphObject status = createStatusUpdate("");
    GraphObject createdStatus = batchCreateAndGet(session, "me/feed", status, null, GraphObject.class);
    String statusID = (String) createdStatus.getProperty("id");

    GraphObject comment = GraphObject.Factory.create();
    final String commentMessage = "It truly is a wonderful status update.";
    comment.setProperty("message", commentMessage);

    GraphObject createdComment1 = batchCreateAndGet(session, statusID + "/comments", comment, null,
            GraphObject.class);
    assertNotNull(createdComment1);

    String comment1ID = (String) createdComment1.getProperty("id");
    String comment1Message = (String) createdComment1.getProperty("message");
    assertNotNull(comment1ID);
    assertNotNull(comment1Message);
    assertEquals(commentMessage, comment1Message);

    // Try posting the same comment to the same status update. We need to clear its ID first.
    createdComment1.removeProperty("id");
    GraphObject createdComment2 = batchCreateAndGet(session, statusID + "/comments", createdComment1, null,
            GraphObject.class);
    assertNotNull(createdComment2);

    String comment2ID = (String) createdComment2.getProperty("id");
    String comment2Message = (String) createdComment2.getProperty("message");
    assertNotNull(comment2ID);
    assertFalse(comment1ID.equals(comment2ID));
    assertNotNull(comment2Message);
    assertEquals(commentMessage, comment2Message);
}
 
Example 8
Source File: Utility.java    From FacebookImageShareIntent with MIT License 5 votes vote down vote up
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;
}
 
Example 9
Source File: TestSession.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 10
Source File: Utility.java    From android-skeleton-project with MIT License 5 votes vote down vote up
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;
}
 
Example 11
Source File: TestSession.java    From platform-friends-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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));
    }
}
 
Example 12
Source File: Utility.java    From KlyphMessenger with MIT License 5 votes vote down vote up
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;
}
 
Example 13
Source File: Utility.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: Utility.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 15
Source File: TestSession.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 16
Source File: Utility.java    From FacebookNewsfeedSample-Android with Apache License 2.0 5 votes vote down vote up
public static boolean queryAppAttributionSupportAndWait(final String applicationId) {

        synchronized (LOCK) {

            // Cache the last app checked results.
            if (applicationId.equals(lastAppCheckedForAttributionStatus)) {
                return attributionAllowedForLastAppChecked;
            }

            Bundle supportsAttributionParams = new Bundle();
            supportsAttributionParams.putString(APPLICATION_FIELDS, SUPPORTS_ATTRIBUTION);
            Request pingRequest = Request.newGraphPathRequest(null, applicationId, null);
            pingRequest.setParameters(supportsAttributionParams);

            GraphObject supportResponse = pingRequest.executeAndWait().getGraphObject();

            Object doesSupportAttribution = false;
            if (supportResponse != null) {
                doesSupportAttribution = supportResponse.getProperty(SUPPORTS_ATTRIBUTION);
            }

            if (!(doesSupportAttribution instanceof Boolean)) {
                // Should never happen, but be safe in case server returns non-Boolean
                doesSupportAttribution = false;
            }

            lastAppCheckedForAttributionStatus = applicationId;
            attributionAllowedForLastAppChecked = ((Boolean)doesSupportAttribution == true);
            return attributionAllowedForLastAppChecked;
        }
    }
 
Example 17
Source File: TestSession.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 18
Source File: Utility.java    From HypFacebook with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static boolean queryAppAttributionSupportAndWait(final String applicationId) {

        synchronized (LOCK) {

            // Cache the last app checked results.
            if (applicationId.equals(lastAppCheckedForAttributionStatus)) {
                return attributionAllowedForLastAppChecked;
            }

            Bundle supportsAttributionParams = new Bundle();
            supportsAttributionParams.putString(APPLICATION_FIELDS, SUPPORTS_ATTRIBUTION);
            Request pingRequest = Request.newGraphPathRequest(null, applicationId, null);
            pingRequest.setParameters(supportsAttributionParams);

            GraphObject supportResponse = pingRequest.executeAndWait().getGraphObject();

            Object doesSupportAttribution = false;
            if (supportResponse != null) {
                doesSupportAttribution = supportResponse.getProperty(SUPPORTS_ATTRIBUTION);
            }

            if (!(doesSupportAttribution instanceof Boolean)) {
                // Should never happen, but be safe in case server returns non-Boolean
                doesSupportAttribution = false;
            }

            lastAppCheckedForAttributionStatus = applicationId;
            attributionAllowedForLastAppChecked = ((Boolean)doesSupportAttribution == true);
            return attributionAllowedForLastAppChecked;
        }
    }
 
Example 19
Source File: Session.java    From FacebookImageShareIntent with MIT License 4 votes vote down vote up
/**
 * This parses a server response to a call to me/permissions.  It will return the list of granted permissions.
 * It will optionally update a session with the requested permissions.  It also handles the distinction between
 * 1.0 and 2.0 calls to the endpoint.
 *
 * @param session An optional session to update the requested permission set
 * @param response The server response
 * @return A list of granted permissions or null if an error
 */
static List<String> handlePermissionResponse(Session session, Response response) {
    if (response.getError() != null) {
        return null;
    }

    GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
    if (result == null) {
        return null;
    }

    GraphObjectList<GraphObject> data = result.getData();
    if (data == null || data.size() == 0) {
        return null;
    }
    List<String> allPermissions = new ArrayList<String>(data.size());
    List<String> grantedPermissions = new ArrayList<String>(data.size());

    // Check if we are dealing with v2.0 or v1.0 behavior until the server is updated
    GraphObject firstObject = data.get(0);
    if (firstObject.getProperty("permission") != null) { // v2.0
        for (GraphObject graphObject : data) {
            String permission = (String) graphObject.getProperty("permission");
            String status = (String) graphObject.getProperty("status");
            allPermissions.add(permission);
            if(status.equals("granted")) {
                grantedPermissions.add(permission);
            }
        }
    } else { // v1.0
        Map<String, Object> permissionsMap = firstObject.asMap();
        for (Map.Entry<String, Object> entry : permissionsMap.entrySet()) {
            if (entry.getKey().equals("installed")) {
                continue;
            }
            allPermissions.add(entry.getKey());
            if ((Integer)entry.getValue() == 1) {
                grantedPermissions.add(entry.getKey());
            }
        }
    }

    // If we have a session track all the permissions that were requested
    if (session != null) {
        session.addRequestedPermissions(allPermissions);
    }
    return grantedPermissions;
}
 
Example 20
Source File: Session.java    From Abelana-Android with Apache License 2.0 4 votes vote down vote up
/**
 * This parses a server response to a call to me/permissions.  It will return the list of granted permissions.
 * It will optionally update a session with the requested permissions.  It also handles the distinction between
 * 1.0 and 2.0 calls to the endpoint.
 *
 * @param response The server response
 * @return A list of granted permissions or null if an error
 */
static PermissionsPair handlePermissionResponse(Response response) {
    if (response.getError() != null) {
        return null;
    }

    GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
    if (result == null) {
        return null;
    }

    GraphObjectList<GraphObject> data = result.getData();
    if (data == null || data.size() == 0) {
        return null;
    }
    List<String> grantedPermissions = new ArrayList<String>(data.size());
    List<String> declinedPermissions = new ArrayList<String>(data.size());

    // Check if we are dealing with v2.0 or v1.0 behavior until the server is updated
    GraphObject firstObject = data.get(0);
    if (firstObject.getProperty("permission") != null) { // v2.0
        for (GraphObject graphObject : data) {
            String permission = (String) graphObject.getProperty("permission");
            if (permission.equals("installed")) {
                continue;
            }
            String status = (String) graphObject.getProperty("status");
            if(status.equals("granted")) {
                grantedPermissions.add(permission);
            } else if (status.equals("declined")) {
                declinedPermissions.add(permission);
            }
        }
    } else { // v1.0
        Map<String, Object> permissionsMap = firstObject.asMap();
        for (Map.Entry<String, Object> entry : permissionsMap.entrySet()) {
            if (entry.getKey().equals("installed")) {
                continue;
            }
            if ((Integer)entry.getValue() == 1) {
                grantedPermissions.add(entry.getKey());
            }
        }
    }

    return new PermissionsPair(grantedPermissions, declinedPermissions);
}