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.
In the search bar, on the left, you'll see a little camera icon. When you touch it, a drop-down menu should say "Search by Image." Click that. You should see two choices: Paste the URL of the image or Upload.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With