com.facebook.model.GraphMultiResult Java Examples

The following examples show how to use com.facebook.model.GraphMultiResult. 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: AuthorizationClientTests.java    From FacebookImageShareIntent with MIT License 6 votes vote down vote up
@Override
Request createGetPermissionsRequest(String accessToken) {
    final List<String> permissions = permissionsToReport;
    return new MockRequest() {
        @Override
        public Response createResponse() {
            GraphObject permissionsObject = GraphObject.Factory.create();
            if (permissions != null) {
                for (String permission : permissions) {
                    permissionsObject.setProperty(permission, 1);
                }
            }
            GraphObjectList<GraphObject> data = GraphObject.Factory.createList(GraphObject.class);
            data.add(permissionsObject);

            GraphMultiResult result = GraphObject.Factory.create(GraphMultiResult.class);
            result.setProperty("data", data);

            return new Response(this, null, null, result, false);
        }
    };
}
 
Example #2
Source File: Session.java    From android-skeleton-project 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 #3
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 #4
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);
}
 
Example #5
Source File: Session.java    From facebook-api-android-maven 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);
}