当前位置: 首页>>代码示例>>Java>>正文


Java GraphObject.asMap方法代码示例

本文整理汇总了Java中com.facebook.model.GraphObject.asMap方法的典型用法代码示例。如果您正苦于以下问题:Java GraphObject.asMap方法的具体用法?Java GraphObject.asMap怎么用?Java GraphObject.asMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.facebook.model.GraphObject的用法示例。


在下文中一共展示了GraphObject.asMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handlePermissionResponse

import com.facebook.model.GraphObject; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:57,代码来源:Session.java

示例2: handlePermissionResponse

import com.facebook.model.GraphObject; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:dannegm,项目名称:BrillaMXAndroid,代码行数:55,代码来源:Session.java


注:本文中的com.facebook.model.GraphObject.asMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。