Jam*_*ang 7 facebook facebook-graph-api
我正在使用Graph API获取粉丝页面的墙贴.
我注意到Facebook iOS应用程序本身能够确定其占位符的确切比率.
http://developers.facebook.com/tools/explorer?method=GET&path=facebook%2Ffeed%3Ffields%3Dpicture
{
"data": [
{
"picture": "http://photos-b.ak.fbcdn.net/hphotos-ak-frc1/247019_457846347622804_946521095_s.jpg",
"id": "20531316728_10151883063741729",
"created_time": "2013-05-02T16:57:25+0000"
},
:
:
:
{
"picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash4/223257_10151498310776729_930531604_s.jpg",
"id": "20531316728_10151498193061729",
"created_time": "2012-10-05T18:42:38+0000"
}
],
"paging": {
"previous": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&since=1367513845",
"next": "https://graph.facebook.com/20531316728/feed?fields=picture&limit=25&until=1349462557"
}
}
Run Code Online (Sandbox Code Playgroud)
它在API响应中不包含图片尺寸的信息,我希望我的自定义客户端(如Facebook iOS应用程序)具有正确的占位符大小.
我尝试添加/ facebook/feed?fields =图片,宽度,高度,但没有运气检索相应的信息.
有没有办法从API本身检索图片的高度和宽度参数?
不,API 不会根据 /page_id/feed 或流表中的帖子提要返回所有图片的尺寸。
我提到这一切是因为,你能做的是:
SELECT post_id, created_time, actor_id, attachment, message FROM stream WHERE source_id=PAGE_ID AND created_time<now() LIMIT 50
Run Code Online (Sandbox Code Playgroud)
如果帖子类型是照片:
如果帖子类型是视频:
如果帖子类型是以 fbexternal 开头的链接(提取参数 w 和 h):
如果帖子类型是没有 fbexternal 的链接(Facebook 照片),我们就卡在这里!:
代码原型:
if attachment:
image_url = attachment.media[0].src
if image_url:
m = image_url.photo.images
if m:
if m.src == image_url:
image_width = m.width
image_height = m.height
else: #no dimensions info
if host by fbexternal:
#extract parameter w and h from https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBhfbzbNudc_SE8&w=130&h=130&url=http%3A%2F%2F
image_width = 130
image_height = 130
else:
Stuck here, very hard to get extract photo id based on this url, a lot of work!
Run Code Online (Sandbox Code Playgroud)
总之,我强烈建议您在下载照片后获取图像的宽度和高度。例如,PHP 有 getimagesize 函数,而 python 有 Python Imaging Library (PIL)。
归档时间: |
|
查看次数: |
3751 次 |
最近记录: |