Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to get facebook user image using access_token

I am working on an application that need to login with facebook. This is the first time when i am integrating Fb API in my application. I have start from Getting Started with the Facebook SDK for Android & successfully get fb access_token.
There are three Activitie in my application & what i need to manage is to have logged in user's Profile Image & name on all these Activities when user successfully get login using facebook.
I know, i can query fb GraphAPI & get complete profile data of current logged-in user using access_token. I succeed to get profile data of user by using valid access_token using_
https://graph.facebook.com/me?<access_token>&format=json
I need the profile image of login user as well(which need user's fb_id)
http://graph.facebook.com/<fb_id>/picture?type=large
Is it possible to get user's profile image using access_token?

like image 282
Rupesh Yadav Avatar asked Dec 15 '12 15:12

Rupesh Yadav


People also ask

How can I get Facebook token in android?

Get Your Client TokenSign into your developer account. On the Apps page, select an app to open the dashboard for that app. On the Dashboard, navigate to Settings > Advanced > Security > Client token.


2 Answers

Finally, after a long search, i got the way to access login user's image by using only access_token https://graph.facebook.com/me/picture?access_token=<your_access_token_here>
thanks to @Jess for your valuable answer!

like image 179
Rupesh Yadav Avatar answered Sep 27 '22 18:09

Rupesh Yadav


You don't need an access token to retrieve a user's profile image. Just issue a http GET request on http://graph.facebook.com/YOUR_ID_HERE/picture, so for example:

http://graph.facebook.com/4/picture gets you user id 4's picture, no access token needed.

EDIT:

To fetch the picture without knowing their fb id but with their access token, just execute a GET request on /me?fields=name,picture and you will receive a response with the URL to their profile picture.

See Graph API Tool example:

https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Dname%2Cpicture

like image 43
Jesse Chen Avatar answered Sep 27 '22 17:09

Jesse Chen