簡體   English   中英

無效的OAUTH訪問令牌,在使用應用程序訪問令牌時,Android

[英]Invalid OAUTH access token, when using an application access token, Android

如標題所示,當我嘗試請求獲取安裝了該字段的朋友列表時:

"me/friends?Fields=installed&access_token=..."

我在logcat中收到以下錯誤:

"Invalid OAuth access token"

當查看facebook api時,我看到已安裝的需要帶一個應用程序訪問令牌。 因此,我使用以下命令使用appId和app Secret生成了應用程序訪問令牌:

https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=APP_ID&client_secret=APP_SECRET

下面是代碼:

try {

 JSONObject obj = Util.parseJson(mFacebook.request("me/friends?fields=installed&access_token=..."));

  Log.d("json Response", obj.toString());
  JSONArray array = obj.optJSONArray("data");
  if (array != null) {
                      for (int i = 0; i < array.length(); i++) {
                        //  String name = array.getJSONObject(i).getString("name");

                          String id = array.getJSONObject(i).getString("id");

                          Log.d("Friends: ",id);
                      }
                  } 
  }catch (Exception e){
    Log.d("Friends:", e.getMessage());
  }

任何人任何想法為什么這樣做我一直在尋找。

干杯

身份驗證后得到的是App Access令牌。

報價: Authenticating as an App allows you to obtain an access token which allows you to make request to the Facebook API on behalf of an App rather than a User. This is useful, for example to modify the parameters of your App, create and manage test users, or read your application's insights for example. App access tokens can also be used to publish content to Facebook on behalf of a user who has granted a publishing permission to your application Authenticating as an App allows you to obtain an access token which allows you to make request to the Facebook API on behalf of an App rather than a User. This is useful, for example to modify the parameters of your App, create and manage test users, or read your application's insights for example. App access tokens can also be used to publish content to Facebook on behalf of a user who has granted a publishing permission to your application

來自facebook docs

您需要的是用戶訪問令牌。 請參考 用戶需要驗證身份並授予對您應用的訪問權限,因為您可以訪問其朋友列表。

編輯

要檢查單個用戶,URL為https://graph.facebook.com/ {uid}?fields = installed&access_token = <ACCESS_TOKEN>

您正在嘗試獲取用戶朋友列表,然后檢查是否已安裝該應用程序。 我認為沒有用戶訪問令牌就不可能獲得用戶朋友列表。

編輯2

根據您的評論,假設您有frind的列表。 然后,您無需為每個用戶呼叫,而可以使用FQL。

https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (uid1,uid2)

如果您擁有用戶訪問令牌,則可以直接進行操作。

https://graph.facebook.com/fql?q=SELECT uid,is_app_user from user where uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

希望這能解決您的問題。

不要請求/ / 朋友 -因為使用應用訪問令牌,API不會知道“我”應該是誰-而是請求/ 用戶ID / 朋友

抱歉,我以前做錯了–方式是使用用戶訪問令牌 ,並根據/ me / friends設置請求…

暫無
暫無

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

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