4

我一直在到处寻找,但找不到任何具体信息。

根据最新的 SDK 3.0 文档 http://developers.facebook.com/docs/reference/android/3.0/AccessToken#getPermissions

AccessToken.getPermissions() 返回的权限列表“如果自创建 AccessToken 对象以来已添加或删除权限,则可能已过时”

我的问题是:
有没有办法要求刷新权限列表,以便令牌可以反映 Facebook 保留的最新权限列表?

4

3 回答 3

3

从 Facebook SDK 版本 3.14 开始,Facebook 在 Session 类中添加了 refreshPermissions 方法。

有关更多信息,您可以查看 github 中的源代码: https ://github.com/facebook/facebook-android-sdk/blob/f6c4e4c1062bcc74e5a25b3243f6bee2e32d949e/facebook/src/com/facebook/Session.java#L605

于 2014-07-27T11:56:35.170 回答
0

找到满足我需求的解决方案:

而不是更新我的令牌,我只是进行 FQL 查询来检索我想知道的权限的远程(最新)状态

以下代码查询有关发布权限(官方称为“publish_actions”):

public void asyncQueryIfHasPublishPermissions() {
    String fqlQuery = "SELECT publish_actions FROM permissions WHERE uid = me()";
        Bundle params = new Bundle();
        params.putString("q", fqlQuery);
        Session session = Session.getActiveSession();
        Request request = new Request(session,
            "/fql",                         
            params,                         
            HttpMethod.GET,                 
            new Request.Callback(){         
                public void onCompleted(Response response) {
                    JSONObject graphResponse = response.getGraphObject().getInnerJSONObject();
                    boolean publishPermissions = false;
                    try {
                        if (graphResponse.getJSONArray("data").getJSONObject(0).getInt("publish_actions")==1) {
                            publishPermissions = true;
                        }
                    } catch (JSONException e) {
                        Log.e("FacebookIntegration", "JSON error "+ e.getMessage());
                    }
                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Log.e("FacebookIntegration", "FacebookRequestError "+ error.getErrorMessage());
                    }
                    Log.i("FacebookIntegration", "asyncQueryIfHasPublishPermissions response: "+publishPermissions);
                }                  
        }); 
        Request.executeBatchAsync(request);
}
于 2013-04-11T04:16:14.260 回答
0

Daniele B 给出的解决方案看起来有点吓人,所以我决定自己写。

这不是实际的解决方案,因为它不会升级存储在Session对象中的权限,但它允许我们检查授予我们哪些权限。

    Request.executeGraphPathRequestAsync(facebookSession, "me/permissions", new Request.Callback() {

    @Override
    public void onCompleted(Response response) {
        GraphObject graphObject; 

        List<String> permissionsToGet = new ArrayList<String>();
        try {
        if (response != null && (graphObject = response.getGraphObject()) != null){
            JSONObject permissions = (JSONObject) ((JSONArray) graphObject.getProperty("data")).get(0);
            for (String permission : facebookPermissions){
                if (!permissions.has(permission) || permissions.getInt(permission) != 1){
                    permissionsToGet.add(permission);
                }
            }

            if (!permissionsToGet.isEmpty()){
                //get new permissions
            } else {
                //all needed permissions are available
            }
        }
        } catch (Exception ex){
            //handle error
        }

    }
});
于 2013-05-23T14:16:33.090 回答