2017-03-06 57 views
0

我一直在谷歌搜索,但未能找到一個全面的答案如何訪問我的個人資料的教育和工作領域。我感興趣的是學校和公司用戶的名字。我嘗試使用GraphRequest.newMeRequest()方法。這裏是我的代碼:如何從Facebook上檢索教育和工作圖api android

private void getUserInfoFromResult(LoginResult loginResult){ 
     GraphRequest request=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { 
      @Override 
      public void onCompleted(JSONObject object, GraphResponse response) { 
       try{ 
        JSONObject userObject=response.getJSONObject(); 

        String firstName=userObject.getString("first_name"); 
        String lastName=userObject.getString("last_name"); 

        JSONArray education=userObject.getJSONArray("education"); 
        JSONArray work=userObject.getJSONArray("work"); 
       } 
       catch (JSONException e){ 

       } 
      } 
     }); 

     Bundle parameters=new Bundle(); 
     parameters.putString("fields","first_name,last_name,education,work"); 
     request.setParameters(parameters); 
     request.executeAsync(); 
    } 

我能夠首先檢索用戶名和姓,不過response對象不返回的教育和工作領域。

+0

嘗試使用https://developers.facebook.com/tools/explorer/。有一定的領域需要不同的訪問令牌。教育和工作領域,你需要勾選user_education_history複選框。 – ZeroOne

回答

1

此外還添加訪問教育詳細信息的權限。像...

LoginManager.getInstance().logInWithReadPermissions(Login.this, Collections.singletonList("public_profile, email, user_birthday, user_education_history, user_location"));