这是一个与 facebook sdk 一起使用的简单 curl 函数。不要忘记将路径更改为fb_ca_chain_bundle.crt
.
function curl($url, $certificate = false) {
$c = curl_init($url);
curl_setopt($c, CURLOPT_HTTPGET, true);
curl_setopt($c, CURLOPT_FRESH_CONNECT, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($c, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($c, CURLOPT_CAINFO, dirname(__FILE__) . '/sdk/fb_ca_chain_bundle.crt');
$output = curl_exec($c);
if ($output === false) {
curl_close($c);
return false;
}
curl_close($c);
return $output;
}
这是获取长寿命令牌的方法调用:
§token = curl('https://graph.facebook.com/oauth/access_token?client_id='.
$app_id.'&client_secret='.
$app_secret.'&grant_type=fb_exchange_token&fb_exchange_token='.
$api->getAccessToken());