我是 android 上 facebook sdk 开发的新手,我正在做一个 Graph API 查询以从我的 facebook 个人资料中检索 FriendList 信息。
我正在使用最新的sdk。有解决方案,SOF w.r.t old sdk
但我想使用最新的工具包来实现它。
与我很容易解析的朋友/me/friends
返回JSON
响应的查询。但是,当我尝试通过查询来获取生日等额外信息时,我得到了无效的响应。name
IDs
/me/friends/?fields=birthday
我friends_birthday
也在onCreateView
下面的方法中设置了权限。
这是我的代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_main, container, false);
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_location", "user_birthday", "user_likes","read_friendlists","friends_birthday")); /*setting permissions*/
userInfoTextView = (TextView) view.findViewById(R.id.userInfoTextView);
return view;
}
public void onResume() {
super.onResume();
Session session = Session.getActiveSession();
if (session != null &&
(session.isOpened() || session.isClosed()) ) {
onSessionStateChange(session, session.getState(), null);
}
uiHelper.onResume();
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
userInfoTextView.setVisibility(View.VISIBLE);
Settings.addLoggingBehavior(LoggingBehavior.REQUESTS);
String graphpath="/me/friends?fields=name,birthday";
Request.executeGraphPathRequestAsync(session, graphpath, new Request.Callback(){
@Override
public void onCompleted(Response response) {
try {
userInfoTextView.setText(buildUserInfoDisplay(response));
} catch (JSONException e) {
Log.d(TAG,"JSON exception");
e.printStackTrace();
}
}
});
}
else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
userInfoTextView.setVisibility(View.INVISIBLE);
}
}
private String buildUserInfoDisplay(Response response) throws JSONException {
if(response.getError()!=null)
Log.d(TAG, "null reponse returned...");
GraphObject go = response.getGraphObject();
JSONObject jso = go.getInnerJSONObject();
JSONArray arr = jso.getJSONArray( "data" );
JSONObject json_obj = arr.getJSONObject(2); /*getting the third friend from the list*/
String birthday = json_obj.getString( "birthday");
return birthday;
}