[英]Facebook extending user access token
Facebook documentation says offline_access
is depreca ted.How do I extend the access token for 60 day? Facebook的文档说不建议使用
offline_access
如何将访问令牌延长60天?
I did enabled deprecated offline_access
from advanced settings for app. 我确实从应用程序的高级设置中启用了已弃用的
offline_access
。
you can try to two ways: 1. enable the offline deprecation functionality, and grab the exchanged token value in available and then run cUrl functionality. 您可以尝试两种方法:1.启用脱机弃用功能,并在可用的状态下获取交换的令牌值,然后运行cUrl功能。 After running the cUrl just pass the response value in var_dump().. you could see the access token and the expires date..
运行cUrl之后,只需在var_dump()中传递响应值即可。您可以看到访问令牌和到期日期。
You can use https://developers.facebook.com/docs/howtos/login/extending-tokens/ for long lived access tokens, or https://developers.facebook.com/docs/howtos/login/login-as-app/ for non-expiring app access tokens. 您可以将https://developers.facebook.com/docs/howtos/login/extending-tokens/用于长期访问令牌,或将https://developers.facebook.com/docs/howtos/login/login-as- app /用于未到期的应用访问令牌。 But you probably need the first.
但是您可能需要第一个。
function fb_renew_access_token($args=array()){
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$args["app_id"]."&client_secret=".$args["app_secret"]."&grant_type=fb_exchange_token&fb_exchange_token=".$args["old_token"];
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_URL, $token_url);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
$paramsfb = null;
parse_str($contents, $paramsfb);
return $paramsfb;
}
//to get the extended access token
$extended_access = fb_renew_access_token(array("app_id"=>"4545454544s45454545","app_secret"=>"sdfgds2fg4d2f54g5df4gdsdsfgdsfg54dfg","old_token"=>"54sdf54sd54f35asdgs4ghdsd5sh4d5trh4djhdfj45fdh"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.