Graph Api Reference V10

     
I have a Facebook desktop application & am using the Graph API.I am able to get the access token, but after that is done - I don"t know how to lớn get the user"s ID.

Bạn đang xem: Graph api reference v10

My flow is lượt thích this:

In my redirect page I get the code from Facebook.

Then I persize a HTTPhường request to lớn graph.facebook.com/oauth/access_token with my API key & I get the access token in the response.

From that point on I can"t get the user ID.

Xem thêm: Mã Bưu Chính Bình Định - Mã Bưu Chính (Zipcode) 63 Tỉnh Thành Việt Nam

How can this problem be solved?


*

*

If you want lớn use Graph API lớn get current user ID then just skết thúc a request to:

https://graph.facebook.com/me?access_token=...

*

The easiest way is

https://graph.facebook.com/me?fields=id&access_token="xxxxx"then you will get json response which contains only userid.


*

The facebook acess token looks similar too"1249203702|2.h1MTNeLqcLqw__.86400.129394400-605430316|-WE1iH_CV-afTgyhDPc"

if you extract the middle part by using | to split you get

2.h1MTNeLqcLqw__.86400.129394400-605430316

then split again by -

the last part 605430316 is the user id.

Xem thêm: Nghĩa Của Từ Tactics Là Gì ? Nghĩa Của Từ Tactical Trong Tiếng Việt

Here is the C# code lớn extract the user id from the access token:

public long ParseUserIdFromAccessToken(string accessToken) -WE1iH_CV-afTgyhDPc * WARNING: The structure of the access token is undocumented và may not always fit the pattern above. Use it at your own risk.

UpdateDue lớn changes in Facebook.the preferred method to get userid from the encrypted access token is as follows:

try var fb = new FacebookClient(accessToken); var result = (IDictionary)fb.Get("/me?fields=id"); return (string)result<"id">;catch (FacebookOAuthException) return null;