Rag*_*ngh 8 javascript ajax facebook
我想从Facebook上获取个人资料图片.现在我从facebook获取所有信息,但无法获得用户的个人资料照片.这是我的代码:
function getFBData () {
FB.api('/me', function(response) {
fbinfo = new Array();
fbinfo[0] = response.id;
fbinfo[1] = response.first_name;
fbinfo[2] = response.last_name;
fbinfo[3] = response.email;
FB.api('/me/picture?type=normal', function (response) {
var im = document.getElementById("profileImage").setAttribute("src", response.data.url);
alert(im);
});
Run Code Online (Sandbox Code Playgroud)
如何从此API的响应中获取图片.
Tom*_*yBs 13
为什么不直接使用已检索到的ID并直接显示图像?你为什么需要额外打个电话?
例如
function getFBData () {
FB.api('/me', function(response) {
fbinfo = new Array();
fbinfo[0] = response.id;
fbinfo[1] = response.first_name;
fbinfo[2] = response.last_name;
fbinfo[3] = response.email;
var im = document.getElementById("profileImage").setAttribute("src", "http://graph.facebook.com/" + response.id + "/picture?type=normal");
});
}
Run Code Online (Sandbox Code Playgroud)
例如http://graph.facebook.com/4/picture?type=normal会重定向到Mark Zuck的图片
如果您在记录网址时遇到问题,请确保您获得有效的ID并将网址粘贴到浏览器中.
尝试喜欢
FB.api("/me", {fields: "id,name,picture"}, function(response)
{
FB.api(
{
method: 'fql.query',
query: 'SELECT pid, src_big, src_big_height, src_big_width FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner="' + response.id + '" AND name = "Profile Pictures")'
},
function(data1) {
alert( data1[0].src_big );
}
);
});
Run Code Online (Sandbox Code Playgroud)
这将为您提供图像的链接,您可以适当地使用它
| 归档时间: |
|
| 查看次数: |
20341 次 |
| 最近记录: |