如何获取较大版本的Facebook的缩略图? [英] How to get larger version of Facebook's thumbnail images?

查看:112
本文介绍了如何获取较大版本的Facebook的缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,Facebook API正在返回一个这样的URL,所有的帖子/专辑图片大小为130x130像素:

Right now the Facebook API is returning a URL like this with all post/album images 130x130 pixels in size:


https://fbcdn-sphotos-ha.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/s130x130/10801504_570625556403546_6496651209845129904_n.jpg?oh=dcf8ab3752522532871d2aaab09b6e7e&oe=54E4402F&的 GDA = 1424027679_76464aeeaa5d232b8100d01476af4ec7

https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/s130x130/10801504_570625556403546_6496651209845129904_n.jpg?oh=dcf8ab3752522532871d2aaab09b6e7e&oe=54E4402F&gda=1424027679_76464aeeaa5d232b8100d01476af4ec7

如何根据该网址检索完整(或任何更大的大小)图像?

How do I retrieve a full (or any bigger size) image based on that URL?

例如这个:


https://fbcdn-sphotos-ha.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/p417x417/10801504_570625556403546_6496651209845129904_n.jpg?或者任何类似的东西,哦= cd2b5cb0d74f7306c098de9f56dc6e27& oe = 54E1F4C1& oe = 54E1F4C1& gda = 1423830001_e700bfac39039952bfee55b200c158bf

https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/p417x417/10801504_570625556403546_6496651209845129904_n.jpg?oh=cd2b5cb0d74f7306c098de9f56dc6e27&oe=54E1F4C1&gda=1423830001_e700bfac39039952bfee55b200c158bf



<

or anything like that?

从URL或/v/t1.0-9/删除s130x130的所有其他建议,或用_n或类似的任何东西替换_s都是无效的再试一次 - 如果你不信我,就自己尝试一下。有没有办法让这种情况发生?不确定什么Facebook的家伙已经改变,以禁用...

All the other suggestions of removing s130x130 from the URL, or /v/t1.0-9/, or replacing _s with _n or anything like that aren't valid any more - I've tried them all (try them yourself if you don't believe me). Is there a way to make this happen? Not sure what Facebook guys have changed to disable that...

推荐答案

经过几个小时搜索和拉我的头发,我找到了一个适用于我的解决方案。在我的情况下,我从{page-id} /帖子中提取帖子,但我很确定这也适用于您,看到我曾经使用与您提到的相同的方法获取更大的图像。

After a couple of hours searching and pulling my hair out, I found a solution that works for me. In my case I'm pulling posts from {page-id}/posts, but I'm pretty sure this will work for you too, seeing that I used to get larger images using the same approach as you mention.

这对我有用:

bigger_image="https://graph.facebook.com/" + picture_url_from_facebook.match(/_\d+/)[0].slice(1) + "/picture?type=normal";




  • / _ \d + /匹配从下划线开始的任何子字符串_)后跟任何数字(\d匹配一个数字,\d +数字匹配一遍又一遍,直到失败)

  • match(regex)返回一个包含所有字符串的数组可以找到匹配指定的正则表达式

  • 我们抓住第一个([0])元素,因为这将是一个下划线,后面是Facebook数据库中的图片ID

  • 我们将字符串从索引1切割到最后,因为下划线不是ID的一部分。

  • 然后我们使用图形API获取一个来自facebook的工作链接,而不是需要任何额外的电话(您可以直接使用这个例如一个img标签)

    • /_\d+/ matches any substring starting with an underscore (_) followed by any digits (\d matches one digit, \d+ does the digit match over and over until it fails)
    • match(regex) returns an array with all strings it could find matching the specified regex
    • we grab the first ([0]) element, as this will be an underscore followed by the ID of the picture in Facebook's database
    • we slice the string from index 1 to the end, as the underscore is not a part of the ID
    • we then get a working link from facebook using the graph api without the need for any extra calls (you can use this in for example an img tag directly)
    • 你可以看到这个工作在行动@ 这个小提琴我们为客户提供的这个页面

      You can see this working in action @ this fiddle or this page we did for a client

      T打破呃Adhish 引领解决方案@ https://stackoverflow.com/a/27075503/2908761

      Thanks to Er Adhish for leading the way to the solution @ https://stackoverflow.com/a/27075503/2908761

      这篇关于如何获取较大版本的Facebook的缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆