如果已经授权的用户现在需要更多权限,如何在canvas应用程序中的signed_request中获取access_token?

Dhr*_*hak 1 php facebook facebook-graph-api facebook-canvas

让我们假设一个画布应用程序的以下情况:

i)第1天: - 创建需要read_stream,publish_stream,offline_access权限的Facebook应用程序 .当用户第一次访问应用程序时,authorize调用会将用户重定向到权限允许/拒绝屏幕,并且当用户允许时将用户重定向回画布URL.

画布URL在其请求参数中的签名请求中具有access_token,然后可以使用该参数来运行应用程序.

下次进入应用程序的同一用户不需要权限对话框,因为如果用户过去授权了应用程序,则signed_request包含acess_token.

代码如下:

if(access_token received from signed request)
// do something with user information
else
// redirect user for authorization flow
Run Code Online (Sandbox Code Playgroud)

ii)第2天: - 现在,假设我想在我的列表中添加一个权限,user_birthday read_stream,publish_stream,offline_access,user_birthday`现在,以下逻辑将出现问题

  if(access_token received from signed request)
    // do something with user information  <-- the access_token does not have new permission
    else
    // redirect user for authorization flow
Run Code Online (Sandbox Code Playgroud)

如果API调用会影响应用程序的性能,那么如何有效地解决这一额外的权限问题呢?我不想使用类似的东西:

https://graph.facebook.com/me/permissions?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)

每次加载应用程序以检查与令牌相关的权限.

更新:

共享一个好的方法:存储权限集以及接收它的access_token.例如.如果当前权限是"basic_details-birthday-publish"(让我们称之为1),请将access_token和权限集存储为

user  | access_token  | perm_set
Dhruv      sdfsdfsdf       1
Run Code Online (Sandbox Code Playgroud)

现在,在您的设置中,无论何时需要请求新权限,都要创建一个新的权限集"basic_details-birthday-publish-checkins"(让我们称之为2),

那么你需要只为拥有perm_set = 1的访问令牌的用户显示权限对话框,而不是已经有perm_set = 2的用户,这样就不需要用"/ me/permissions"检查每个用户的access_token API.

Bjö*_*ser 5

这将是一个两步过程:

  1. 通过向图形路径"/ me/permissions"发出请求,检查用户是否授予您所有必需的权限

  2. 如果用户未授予您所有必需的权限,则需要通过通常的允许/拒绝过程,但这次将新权限添加到"scope"参数中.

Edit_:我知道验证权限的唯一可靠方法是调用/ me/permissions.