在 Facebook iOS SDK v4.x 中撤销权限未更新 currentAccessToken 权限

Revoking permissions in Facebook iOS SDK v4.x not updating currentAccessToken permissions

在我的应用程序中,我想使用 Facebook iOS SDK 的 v4.x 撤销 Facebook 的 publish_actions 权限。 (我在版本 4.5.1 上使用 FBSDKCoreKitFBSDKLoginKitFBSDKShareKit 作为 pods。)它的工作方式与我预期的一样 - 它 returns 成功,然后当我使用 Graph API Explorer 获取我的权限时,它显示 publish_actions 被拒绝。但是,如果我这样做后在本地检查 FBSDKAccessToken 的权限,它不会说 publish_actions 已被拒绝。我认为这是因为 FBSDKAccessToken 被缓存了。因为我没有在文档中看到需要更新它,所以我假设我错过了什么或者只是做错了什么。所以我想知道是否有人遇到过这个问题并且有解决办法。

我用来撤销权限的代码如下:

request = FBSDKGraphRequest.alloc.initWithGraphPath("me/permissions/publish_actions",
                  parameters: {"fields" => ""},
                  tokenString: FBSDKAccessToken.currentAccessToken.tokenString,
                  version: nil,
                  HTTPMethod: "DELETE")
connection = FBSDKGraphRequestConnection.new

connection.addRequest(request, completionHandler: lambda {|connection, result, error|
  if !error && result["success"] == true
    # Revoking the permission worked
  else
    # Things went wrong
  end
})
connection.start

我想通了。我认为 FBSDKAccessTokenrefreshCurrentAccessToken 触发了另一次重新授权,但事实并非如此。所以在撤销权限后简单地调用它会刷新权限状态。就像文档说的那样!这是我的完整方法:

request = FBSDKGraphRequest.alloc.initWithGraphPath("me/permissions/publish_actions",
                  parameters: {"fields" => ""},
                  tokenString: FBSDKAccessToken.currentAccessToken.tokenString,
                  version: nil,
                  HTTPMethod: "DELETE")
connection = FBSDKGraphRequestConnection.new

connection.addRequest(request, completionHandler: lambda {|connection, result, error|
  if !error && result["success"] == true
    # if revoke is successful, refresh permissions cache so
    # FBSDKAccessToken no longer says publish_actions is enabled
    FBSDKAccessToken.refreshCurrentAccessToken(lambda {|connection, result, error|
      # FBSDKAccessToken permission state is up to date
      alertTitle = "Permission successfully revoked";
      alertText = "This app will no longer post to Facebook on your behalf."
    })
  else
    alert("There was an error", error.description)
  end
})
connection.start