簡體   English   中英

如何在Android中使用令牌從Facebook獲取用戶ID

[英]How to get user ID from Facebook using token in Android

*I am easily getting a token from my app but when I am trying to get the ID or user ID, I can't.

    Facebook authenticatedFacebook = new Facebook(APP_ID);

After this I call the Facebook API and get a token.

    String token=data.getStringExtra("access_token");
    jsonobj=new JSONObject(authenticatedFacebook.request("https://graph.facebook.com/me?access_token="+token));

or

    jsonobj=new JSONObject(authenticatedFacebook.request("/me?access_token="+token));

or

    jsonobj=new JSONObject(authenticatedFacebook.request("me?access_token="+token));
    //  jsonresponseArray=jsonobj.getJSONArray("id");
    System.out.println("the id has"+jsonobj.has("id"));
String usrid=jsonobj.getString("id");
so it give me error that it doesn't have any id field.
So please, can you give me a solution? And thanks in advance.*

您好,您可以按照以下幾行進行操作:

/ me返回帶有id字段(和其他字段)的JSON對象。 您可以這樣解析此JSON對象:

JSONObject json = Util.parseJson(facebook.request("me", params));
String userId = json.getString("id");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM