如何使用curl获取长寿命access_token?

时间:2012-03-31 11:57:20

标签: php facebook facebook-graph-api curl

如何使用curl获取长寿命access_token并将其存储在变量中?

我的网络主机无法使用file_get_contents()由于某些原因导致我无法使用此选项以便我可以使用下一个选项是使用我知道的CUrl并学习但我不明白。< / p>

下面是我们用来获取长寿命的网址access_token note我已经在$ atoken存储了access_token

https://graph.facebook.com/oauth/access_token?client_id="id"&client_secret="its seceret ;)"&grant_type=fb_exchange_token&fb_exchange_token=$atoken 

谢谢

1 个答案:

答案 0 :(得分:1)

像这样制作简单的cURL请求

$url = 'https://graph.facebook.com/oauth/access_token?client_id="id"&client_secret="its  seceret ;)"&grant_type=fb_exchange_token&fb_exchange_token=$atoken';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "I-am-browser");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);


var_dump(json_decode($response, true));