graph.facebook.com/me/home照片的宽度和高度

时间:2013-08-01 01:47:34

标签: facebook facebook-graph-api

如何从/me/home获取照片的宽度和高度?

我试试

/me/home?fields=picture,width,height

但没有宽度和高度的结果。

1 个答案:

答案 0 :(得分:0)

图谱API不会根据宽度和高度返回图像的大小。 但是,您可以使用“height”和“width”参数指定要检索的大小,例如:

me/picture?width=70&height=90

此外,您可以使用'type'参数检索一些默认大小: https://developers.facebook.com/docs/reference/api/using-pictures/#sizes

最后,您可以检索任何大小的图片,并以编程方式获取其宽度和高度。

Javascript示例:

现代浏览器和IE9 +:

var width = document.getElementById('yourImg').naturalWidth,
    height = document.getElementById('yourImg').naturalHeight;
console.log(width, height);

对于IE8 - :

var img = new Image(), // or document.createElement('img')
    width,
    height;

img.onload = function() {
  width = this.width;
  height = this.height;
};

img.src = 'http://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/626_someid_202729_q.jpg'
console.log(width, height);
相关问题