简体   繁体   English

Facebook Android 3.0从访问令牌获取用户信息

[英]Facebook Android 3.0 get user information from access token

In the SessionLoginSample example from the Facebook for Android 3.0 SDK, the LoginActivity returns an access token in the session object. 在Facebook for Android 3.0 SDK的SessionLoginSample示例中,LoginActivity在会话对象中返回访问令牌。

How do I get user information from this access token? 如何从此访问令牌获取用户信息?

Do I need to manually write a network call to the /me url endpoint, or is there a mechanism within the Facebook Android SDK which will do this for me using the access token 我是否需要手动将网络呼叫写入/me url端点,或者Facebook Android SDK中是否有一种机制可以使用访问令牌为我执行此操作

The access token provides you the possibility of making request to the Facebook APIs accordingly to the access type and permissions related to it. 访问令牌使您可以根据访问类型和与之相关的权限向Facebook API发出请求。 With this you can manually do Graph API requests, that are low-level HTTP-based API. 有了这个,你可以手动执行Graph API请求,这是基于HTTP的低级API。 (See also the Graph API Explorer ) (另请参见Graph API Explorer

If instead you want to benefit from the SDK I suggest you to set up an Android project following the Getting Started guide . 如果您希望从SDK中受益,我建议您按照入门指南设置Android项目。 In fact the SessionLoginSample already uses more complex objects (like sessions), in order to avoid to using "explicitly" the Graph API. 事实上,SessionLoginSample已经使用了更复杂的对象(如会话),以避免使用“显式”Graph API。

Use the Request.newMeRequest method. 使用Request.newMeRequest方法。 Pass in the session, and a callback, and it will call you back once it finishes. 传递会话和回调,它会在完成后回叫你。

Request meRequest = Request.newMeRequest(Session.getActiveSession(), new Request.GraphUserCallback() { ... });
meRequest.executeAsync();

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

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