我一直在寻找,但我找不到任何具体的信息。
根据最新的SDK 3.0文档 http://developers.facebook.com/docs/reference/android/3.0/AccessToken#getPermissions:
如果自创建AccessToken对象以来添加或删除了权限,则AccessToken.getPermissions()返回的权限列表“可能已过时”
我的问题是:
有没有办法要求刷新权限列表,以便令牌可以反映Facebook保留的最新权限列表?
答案 0 :(得分:3)
自Facebook SDK 3.14版以来,Facebook将refreshPermissions方法添加到Session类中。
有关更多信息,您可以在github中查看源代码: https://github.com/facebook/facebook-android-sdk/blob/f6c4e4c1062bcc74e5a25b3243f6bee2e32d949e/facebook/src/com/facebook/Session.java#L605
答案 1 :(得分: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);
}
答案 2 :(得分: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
}
}
});