简体   繁体   English

Android:如何使用access_token获取Facebook用户图像

[英]Android: How to get facebook user image using access_token

I am working on an application that need to login with facebook . 我正在开发一个需要login with facebook的应用程序。 This is the first time when i am integrating Fb API in my application. 这是我第一次在我的应用程序中集成Fb API。 I have start from Getting Started with the Facebook SDK for Android & successfully get fb access_token . 我从Facebook SDK for Android入门开始并成功获得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. 我的应用程序中有三个Activitie ,我需要管理的是当用户使用facebook成功登录时,在所有这些Activities登录用户的个人资料图像和名称。
I know, i can query fb GraphAPI & get complete profile data of current logged-in user using access_token. 我知道,我可以使用access_token查询fb GraphAPI并获取当前登录用户的完整配置文件数据。 I succeed to get profile data of user by using valid access_token using_ 我成功通过使用有效的access_token使用_获取用户的个人资料数据
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 ) 我也需要登录用户的个人资料图片(需要用户的fb_id
http://graph.facebook.com/<fb_id>/picture?type=large
Is it possible to get user's profile image using access_token ? 是否可以使用access_token获取用户的个人资料图像?

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> 最后,经过长时间的搜索,我只使用access_token访问登录用户的图像https://graph.facebook.com/me/picture?access_token=<your_access_token_here>
thanks to @Jess for your valuable answer! 感谢@Jess的宝贵答案!

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/YOUR_ID_HERE/picture上发出http GET请求,例如:

http://graph.facebook.com/4/picture gets you user id 4's picture, no access token needed. http://graph.facebook.com/4/picture为您提供用户ID 4的图片,无需访问令牌。

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. 要在不知道他们的fb id但是使用他们的访问令牌的情况下获取图片,只需在/me?fields=name,picture上执行GET请求,您将收到带有他们个人资料图片的URL的响应。

See Graph API Tool example: 请参阅图谱API工具示例:

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

So after messing around with the facebook graph apis for a bit, I have found that you can get the profile pic in two ways: 所以在弄乱了facebook图表apis之后,我发现你可以通过两种方式获得个人资料图片:

  1. Use this as the profile pic url by substituting the user id: https://graph.facebook.com/USER_ID/picture?return_ssl_resources=1 通过替换用户ID将其用作配置文件pic url: https//graph.facebook.com/USER_ID/picture?return_ssl_resources = 1

  2. Using the access token: https://graph.facebook.com/me/picture?access_token=ACCESS_TOKEN 使用访问令牌: https//graph.facebook.com/me/picture?access_token = ACCESS_TOKEN

Hope this is helpful. 希望这是有帮助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM