文件获取内容再次不起作用的替代方案


file get contents again not working alternative

我尝试了curl,因为现在在php中工作的filegetcontents可以给我解决方案吗?所以使用curl解决它。这里是代码

$userData = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'),true);
print($userData[id]).'<br/>';

这个怎么样:

$cFb = curl_init(
    'https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'
);
curl_setopt($cFb, CURLOPT_RETURNTRANSFER, true);
$userData = json_decode(curl_exec($cFb), true);
curl_close($cFb);
print($userData['id']).'<br/>';

尽管正如Abhik Chakraborty在评论中所建议的那样,使用官方的Facebook PHP SDK可能值得一试。SDK使用curl,因此它应该在您的托管环境中工作。

试试这个:

$json = json_decode(file_get_contents('https://graph.facebook.com/me?access_token='.$token.'&fields=name,id'),true);
$json_output = json_decode($json, true);

现在你可以得到这样的特定项目:

echo $json_output['id'];