如何使用FB.api('/ me / picture')获取配置文件图像 [英] How to use FB.api('/me/picture') to get profile image

查看:577
本文介绍了如何使用FB.api('/ me / picture')获取配置文件图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常愚蠢的问题。我是一个初学者与Facebook的JavaScript SDK。
所以我试图使一个用户的个人资料图像显示
我使用这个代码

  FB.api('/ me',function(response){
document.getElementById('login')。style.display =block;
document.getElementById('login')innerHTML = '< img src =http://graph.facebook.com/'+ response.id +'/ picture/>';
});

哪些工作正常,但我正在努力了解如何使用 FB .api('/ me / picture')显示图像。

解决方案

/ me / picture (或 / {user id} / picture )返回HTTP 301重定向到图像位置,以便您可以将其直接嵌入到< img src ...



如果您想要检索URL并自行使用,您需要通过以下方式专门请求该字段:

  / {user id}?fields = picture 

  / me /?fields = picture 

您也可以包含其他字段,但我假设您只是想要照片。


This is a very silly question. I'm a beginner with facebook Javascript SDK. So I'm trying to make a the user's profile image to show I used this code

FB.api('/me', function(response) {      
    document.getElementById('login').style.display = "block";
    document.getElementById('login').innerHTML = '<img src="http://graph.facebook.com/' + response.id + '/picture" />';
});

which worked fine, but I'm trying to understand how to use FB.api('/me/picture') to show the image.

解决方案

/me/picture (or /{user id}/picture) returns an HTTP 301 redirect to the image location so you can embed it directly into an <img src...

If you want to retrieve the URL and use it yourself you need to specifically request it as a field, via :

 /{user id}?fields=picture

or

 /me/?fields=picture

You can include other fields too, but I'm assuming you just want the photo right now.

这篇关于如何使用FB.api('/ me / picture')获取配置文件图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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