使用PHP检索用户的Facebook照片的问题
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?
过去几天我睡不着觉,我的一个客户已经结束了 将网站迁移到新托管后的世界问题,我无法弄清楚。 这个问题非常简单 - 检索用户的Facebook照片。 到目前为止这个工作正常,但显然新服务器上的某些设置导致它失败。 问题是 p>
返回一个空字符串。 我还尝试使用另一个不依赖于访问令牌的URL(尽管访问令牌有效,因为我得到了有关用户的其他信息): p>
其中 我检查了服务器设置,openssl已启用,allow_url_fopen也已启用。 关于还有什么可能导致这种情况的任何想法? p>
div> file_get_contents('https://graph.facebook.com/me/picture?access_token=VALID_ACCESS_TOKEN&type=large') code> p>
file_get_contents ('https://graph.facebook.com/'.$user->id.'/picture?type=large') code> p>
$ user-> id code>是用户的Facebook ID。 在浏览器中手动打开上面的URL显示照片,使用我本地服务器上的相同代码也显示它们,但在网站上结果总是一个空字符串,没有错误,没有例外。 p>
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