我正在设计一个Facebook应用程序,并试图获取我朋友的"位置"。使用Graph API资源管理器工具:http://developers.facebook.com/tools/explorer/这是一个瞬间。
然而,当我从经过身份验证的应用程序用户处调用以获取访问令牌时,我收到的令牌比从Graph API资源管理器工具生成的令牌短。这个缩短的令牌允许我接收基本的朋友信息,但不允许我检索位置对象。做一些研究似乎表明我错过了代币的"会话部分"http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
如何检索此"会话部分"为什么我从Facebook收到的令牌与我从Graph Explorer API收到的令牌不同?
注意:我确保我正在请求必要的扩展权限来读取我朋友的位置。
确保您有用户access_token
。如果您正在使用PHP-SDK,那么很可能您正在使用应用程序access_token
。
如果没有用户access_token
,SDK将始终获取应用程序access_token
并使用它(参考):
/**
* Determines the access token that should be used for API calls.
* The first time this is called, $this->accessToken is set equal
* to either a valid user access token, or it's set to the application
* access token if a valid user access token wasn't available. Subsequent
* calls return whatever the first call returned.
*
* @return string The access token
*/
public function getAccessToken() {
if ($this->accessToken !== null) {
// we've done this already and cached it. Just return.
return $this->accessToken;
}
// first establish access token to be the application
// access token, in case we navigate to the /oauth/access_token
// endpoint, where SOME access token is required.
$this->setAccessToken($this->getApplicationAccessToken());
$user_access_token = $this->getUserAccessToken();
if ($user_access_token) {
$this->setAccessToken($user_access_token);
}
return $this->accessToken;
}