【问题标题】:file get contents again not working alternative文件再次获取内容无法正常工作
【发布时间】:2014-06-09 18:54:11
【问题描述】:

我尝试了 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/>';

【问题讨论】:

  • 对于 Facebook Graph API,file_get_contents() 应该可以工作,并且它们永远不会关闭访问。问题出在其他地方。您是否尝试过 grpah exploer 看看这是否有效?
  • 感谢编辑:)
  • 不,问题是我的主机不支持该功能。 graph api 可以完美运行,但问题出在我的主机上,所以我必须改用 curl
  • 在这种情况下,为什么不使用 FB 的 PHP 库。您正在尝试的可以通过使用 api 端点 /me 来完成
  • no bro thay 不工作我试过正常情况下它工作。我的意思是我想清理过期的令牌。为此,我必须使用它。因为我必须删除过期的令牌。所以必须使用上面的代码。

标签: php facebook curl


【解决方案1】:

这个怎么样:

$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 在 cmets 中所建议的那样,使用官方 Facebook PHP SDK 可能值得考虑。 SDK 使用 curl,因此它应该可以在您的托管环境中运行。

【讨论】:

  • 好的,兄弟。我一定会尝试的。我现在在暴民中。我一定会回复并发表评论
【解决方案2】:

试试这个:

$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'];  

【讨论】:

    猜你喜欢
    • 2012-02-03
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多