php – facebook图api从2.2到2.3不起作用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – facebook图api从2.2到2.3不起作用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2960字,纯文字阅读大概需要5分钟。
内容图文
因为它是图api 2.2的截止日期,所以我正在尝试使用v2.3修复我的图形api
但是当我使用2.3时,我发现大多数api请求响应没有,但我在升级文档中找不到任何更新.例如:
https://graph.facebook.com/v2.3/{$user_id}?date_format=U&fields=albums.order(reverse_chronological).limit(100).offset(0){id,count,name,created_time}
如果我使用2.3,将不会返回任何内容
我致电时无法获得用户的生日:
https://graph.facebook.com/v2.3/{$user_id}
它只是返回名称和实时位置.
但在v2.2中,它包括生日简介.
我使用facebook SDK 3.2.2,因为我的php版本是5.3.
有什么更新我不知道吗?谢谢.
解决方法:
我自己发现了这个问题.这是因为SDK 3.2.2.对于Facebook更新(从API版本2.3的Changelog):
[Oauth Access Token] Format – The response format of 07001 returned when you exchange a code for an access_token now return valid JSON instead of being URL encoded. The new format of this response is {“access_token”: {TOKEN}, “token_type”:{TYPE}, “expires_in”:{TIME}}. We made this update to be compliant with section 5.1 of RFC 6749.
但SDK将响应识别为数组(在getAccessTokenFromCode函数中):
$response_params = array();
parse_str($access_token_response, $response_params);
if (!isset($response_params['access_token'])) {
return false;
}
return $response_params['access_token'];
这将无法正确获取用户访问令牌,并且您无法获取用户的数据.所以你应该更新这个函数来解析数据为json:
$response = json_decode($access_token_response);
if (!isset($response->access_token)) {
return false;
}
return $response->access_token;
然后所有功能将照常工作.
此外,您必须对setExtendedAccessToken()进行类似的更改.否则,您的应用将无法扩展访问令牌.下面的代码演示了如何升级该功能.
/**
* Extend an access token, while removing the short-lived token that might
* have been generated via client-side flow. Thanks to http://bit.ly/ b0Pt0H
* for the workaround.
*/
public function setExtendedAccessToken() {
try {
// need to circumvent json_decode by calling _oauthRequest
// directly, since response isn't JSON format.
$access_token_response = $this->_oauthRequest(
$this->getUrl('graph', '/oauth/access_token'),
$params = array(
'client_id' => $this->getAppId(),
'client_secret' => $this->getAppSecret(),
'grant_type' => 'fb_exchange_token',
'fb_exchange_token' => $this->getAccessToken(),
)
);
}
catch (FacebookApiException $e) {
// most likely that user very recently revoked authorization.
// In any event, we don't have an access token, so say so.
return false;
}
if (empty($access_token_response)) {
return false;
}
//Version 2.2 and down (Deprecated). For more info, see https://stackoverflow.com/a/43016312/114558
// $response_params = array();
// parse_str($access_token_response, $response_params);
//
// if (!isset($response_params['access_token'])) {
// return false;
// }
//
// $this->destroySession();
//
// $this->setPersistentData(
// 'access_token', $response_params['access_token']
// );
//Version 2.3 and up.
$response = json_decode($access_token_response);
if (!isset($response->access_token)) {
return false;
}
$this->destroySession();
$this->setPersistentData(
'access_token', $response->access_token
);
}
内容总结
以上是互联网集市为您收集整理的php – facebook图api从2.2到2.3不起作用全部内容,希望文章能够帮你解决php – facebook图api从2.2到2.3不起作用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。