检索用户时出现问题使用 PHP 的 Facebook 照片
过去几天我的睡眠质量严重落后,我的一个客户在将网站移至新主机后遇到了世界末日的问题,我无法弄清楚。这个问题非常简单——检索用户的 Facebook 照片。到目前为止,这一切都很好,但显然新服务器上的某些设置导致它失败。问题是
file_get_contents('https://graph.facebook.com/me/picture?access_token=VALID_ACCESS_TOKEN&type=large')
返回一个空字符串。我还尝试使用另一个网址,它不依赖于访问令牌(尽管访问令牌是有效的,因为我获得了有关用户的其他信息):
file_get_contents('https://graph.facebook.com /'.$user->id.'/picture?type=large')
其中 $user->id
是用户的 Facebook ID。在浏览器中手动打开上述网址会显示照片,在我的本地服务器上使用相同的代码也会显示它们,但在网站上结果始终是空字符串,没有错误,没有例外。
我检查了服务器设置,openssl 已启用,allow_url_fopen 也已启用。关于还有什么可能导致这种情况的任何想法吗?
I'm way behind with my sleep for the last few days and a client of mine has an end-of-the-world problem after moving a website to a new hosting, which I can't figure out. The issue is quite trivial - retrieving the Facebook photo of users. This worked just fine until now, but apparently some setting on the new server are causing it to fail. The problem is that
file_get_contents('https://graph.facebook.com/me/picture?access_token=VALID_ACCESS_TOKEN&type=large')
returns an empty string. I also tried using another url, which doesn't rely on an access token (although, the access token is valid, because I get other info about the user):
file_get_contents('https://graph.facebook.com/'.$user->id.'/picture?type=large')
where $user->id
is the Facebook ID of the user. Manually opening the above URLs in the browser shows the photo, using the same code on my local server also shows them, but on the website the result is always an empty string, no errors, no exceptions.
I checked server settings, openssl is enabled, allow_url_fopen also. Any ideas as to what else can be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会遇到麻烦,因为
//picture
返回到图像的 HTTP 301 重定向(即您可以将其直接包含在中)。
)尝试查询
/?fields=picture
并解析该响应中的 URL,而不是尝试直接包含它You may be having trouble because
/<user>/picture
returns a HTTP 301 redirect to the image (i.e you can include it directly in an<img src=""/>
)Try querying
/<user>?fields=picture
and parsing the URL from that response, rather than trying to directly include it