php Facebook Graph API 更改:图片类型(大小)不再有效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11982276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Graph API Change: Picture type (size) no longer working?
提问by Metal450
According to Facebook's Graph API documentation (here), you can access various sizes of a user's profile picture through URLs such as:
根据 Facebook 的 Graph API 文档(此处),您可以通过 URL 访问各种大小的用户个人资料图片,例如:
https://graph.facebook.com/(userid)/picture?type=small
https://graph.facebook.com/(userid)/picture?type=large
You'll notice that the first resolves to a url ending in _t.jpg (the small thumbnail) and the second ending in _n.jpg (the large image). So far so good. Equivalently, we should be able to query for these images like this:
您会注意到第一个解析为以 _t.jpg(小缩略图)结尾的 url,第二个以 _n.jpg(大图像)结尾。到现在为止还挺好。同样,我们应该能够像这样查询这些图像:
https://graph.facebook.com/(userid)?fields=picture&type=small
https://graph.facebook.com/(userid)?fields=picture&type=large
This latter format worked as expected for many months, until just a few days ago when it suddenly started ignoring the "type" parameter entirely - everything now resolves to an image ending in _q.jpg, which is the default if no "type" is specified. As a result, I can no longer figure out a way to query for the large image in PHP (my realproblem). It used to work like this:
后一种格式按预期工作了好几个月,直到几天前它突然开始完全忽略“类型”参数 - 现在一切都解析为以 _q.jpg 结尾的图像,如果没有“类型”,这是默认值指定的。结果,我再也找不到在 PHP 中查询大图像的方法(我的真正问题)。它曾经是这样工作的:
$pic = $facebook->api('/me', array('fields' => 'picture', 'type' => 'large'));
...but as described above, "type" has spontaneously started being ignored. I've spent several hours scouring their documentation but haven't been able to find any reference to what has changed, or the "new" way this should be done - any pointers would be hugely appreciated...
...但如上所述,“类型”已自发地开始被忽略。我花了几个小时搜索他们的文档,但找不到任何对已更改内容的引用,或者应该以“新”的方式来完成——任何指针都将不胜感激......
EDIT:
编辑:
None of the following work, either (returns nothing):
以下都不起作用(不返回任何内容):
$pic = $facebook->api('/me/picture', array('type' => 'large'));
$pic = $facebook->api('/(my_uid)/picture', array('type' => 'large'));
$pic = $facebook->api('/me/picture/?type=large');
$pic = $facebook->api('/(my_uid)/picture/?type=large');
Basically, since Facebook broke things a few days ago there doesn't seem to be any way to get a non-default picture size from PHP. You can try out some of the calls yourself from the Graph API Explorer (here).
基本上,由于 Facebook 几天前出事了,似乎没有任何方法可以从 PHP 获取非默认图片大小。您可以从 Graph API Explorer(这里)自己尝试一些调用。
Other related/relevant links:
其他相关/相关链接:
http://stackoverflow.com/questions/2978761/facebook-graph-api-will-not-give-me-picture-data
http://stackoverflow.com/questions/7718704/requesting-picture-for-event
采纳答案by Metal450
I found a workaround - profile pictures of various sizes can still be accessed via an FQL query:
我找到了一个解决方法 - 仍然可以通过 FQL 查询访问各种大小的个人资料图片:
$pic = $facebook->api(array('method'=>'fql.query', 'query'=>"SELECT pic_big FROM user WHERE uid=$fb_uid"));
("pic_big" is equivalent to "type=large" - see here).
(“pic_big”等价于“type=large”——见这里)。
This still doesn't explain why the GRAPH call suddenly broke though, or why image sizes don't seem to be accessible via Graph at all anymore (which I'd still like to know)...but at least there's someway to get the other size photos.
这仍然不能解释为什么 GRAPH 调用突然中断,或者为什么图像大小似乎不再可以通过 Graph 访问(我仍然想知道)……但至少有一些方法可以获取其他尺寸的照片。
Gotta love Facebook and their top-notch reliability...
必须喜欢 Facebook 及其一流的可靠性......
回答by VLoppez
You must request the API with the field_expansion syntax
您必须使用field_expansion 语法请求 API
These api requests works :
这些 api 请求有效:
$results = $facebook->api('/me', array('fields' => 'picture.height(300).width(300)'));
$results = $facebook->api('/me', array('fields' => 'picture.height(300).width(300)'));
$results = $facebook->api('/me', array('fields' => 'picture.type(large)'));
$results = $facebook->api('/me', array('fields' => 'picture.type(large)'));
回答by thaddeusmt
As described in this bugon Facebook, you can request this via the new API "field expansion" syntax.
正如Facebook 上的这个 bug所描述的,您可以通过新的 API“字段扩展”语法来请求这个。
This works for me:
这对我有用:
https://graph.facebook.com/____OBJECT_ID____?fields=picture.type(large)

