任何人都可以帮助我使用以下网址将其设为卷曲
$userData = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'),true);print($userData[name]).'<br/>';
答案 0 :(得分:1)
$url = 'https://graph.facebook.com/me?access_token='.$token.'&fields=name,id';
$userData = json_decode(url_get_contents($url), true);
// print($userData[name]);
print_r($userData);
function url_get_contents ($Url) {
if (!function_exists('curl_init')){ die('CURL is not installed!'); }
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
输出
Array
(
[error] => Array
(
[message] => An active access token must be used to query information about the current user.
[type] => OAuthException
[code] => 2500
)
)
答案 1 :(得分:1)
试试这类似于FB PHP SDK
if (!function_exists('curl_init')) {
die('Facebook needs the CURL PHP extension.');
}
//$params = array("access_token"=>$access_token,"fields"=>"name,id");
$opts = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'facebook-php-3.1',
);
$ch = curl_init();
$url = 'https://graph.facebook.com/me?access_token='.$token.'&fields=name,id' ;
$opts[CURLOPT_URL] = $url;
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
if ($result === false) {
curl_close($ch);
die('Error in the response !! ');
}
curl_close($ch);
如果您遇到SSL问题,请从FB SDK库下载fb_ca_chain_bundle.crt
并存储在您的服务器中。