如何从Facebook JavaScript SDK获取个人资料图片? [英] How to fetch profile picture from facebook javascript SDK?

查看:114
本文介绍了如何从Facebook JavaScript SDK获取个人资料图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Facebook获取个人资料图片。现在我从Facebook获取所有信息,但无法获取用户的个人资料图片。这是我的代码:

  function getFBData(){
FB.api('/ me',function ){
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);
});

如何从这个API的响应中获取图片。

解决方案

为什么你不是只使用你已经检索到的id并直接显示图像?为什么需要额外拨打电话?



eg

  function getFBData(){
FB.api('/ me',function(response){
fbinfo = new Array ();
fbinfo [0] = response.id;
fbinfo [1] = response.f irst_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 );
});
}

例如 http://graph.facebook.com/4/picture?type=normal 重定向到Mark Zuck的照片



如果您无法登录网址,以确保您获得了有效的ID,并将该网址粘贴到浏览器中。


I am trying to fetch profile picture from facebook. Right now I am getting all information from facebook but unable to get profile pic of the user. Here is my code:

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);
        }); 

How can I get picture from response of this API.

解决方案

Why don't you just use the id you've already retrieved and display the image directly? Why do you need to make an extra call?

e.g

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");
});
}

For example http://graph.facebook.com/4/picture?type=normal redirects to Mark Zuck's picture

If you're having trouble log the url out to make sure you're getting a valid id back and paste the url into a browser.

这篇关于如何从Facebook JavaScript SDK获取个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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