如何在Android中使用facebook api获取朋友的姓名,生日,个人资料图片和详细信息

时间:2014-04-26 07:20:06

标签: android facebook-graph-api facebook-android-sdk android-facebook

我正在尝试获取朋友数据并在列表视图中显示,直到现在我尝试下面的代码。 但我得到的朋友的名字和身份只是没有得到我/朋友的DOB。

我尝试了以下代码:

if (! facebook.isSessionValid()) {        
facebook.authorize(MainActivity.this, PERMISSIONS, new LoginDialogListener());
}
}     
});
}  

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("FB Demo App", "onActivityResult(): " + requestCode);
facebook.authorizeCallback(requestCode, resultCode, data);
}

private class LoginDialogListener implements DialogListener {

 public void onComplete(Bundle values) {
 saveCredentials(facebook);
 getAlbumsData task = new getAlbumsData();          
 task.execute();
 mHandler.post(new Runnable() {
 public void run() {
 //---        Intent i = new Intent(LoginActivity.this,FrndActivity.class);
//---         i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//---        startActivity(i);
     }
  });
 mAsyncRunner.request("me/friends", new FriendsRequestListener());

  }
 private class FriendsRequestListener implements RequestListener {
 String friendData;

 //Method runs when request is complete
 public void onComplete(String response, Object state) {
 Log.v("", "FriendListRequestONComplete");
  //Create a copy of the response so i can be read in the run() method.
  friendData = response;
 Log.v("friendData--", ""+friendData);


 //Create method to run on UI thread
   MainActivity.this.runOnUiThread(new Runnable() {
      public void run() {
     try {
   //Parse JSON Data

  JSONObject json;
   json = Util.parseJson(friendData);

   //Get the JSONArry from our response JSONObject
   JSONArray friendArray = json.getJSONArray("data");

   Log.v("friendArray--", ""+friendArray);

   for(int i = 0; i< friendArray.length(); i++)
   {
       JSONObject frnd_obj = friendArray.getJSONObject(i);
       friends.add(frnd_obj.getString("name")+"~~~"+frnd_obj.getString("birthday"));


   }
   loginButton.setVisibility(View.INVISIBLE);
   list1.setAdapter(new ArrayAdapter<>(getApplicationContext(),  android.R.layout.simple_list_item_1,friends));

 /*Intent ide = new Intent(MainActivity.this,FrndActivity.class);
       ide.putStringArrayListExtra("friends", friends);
     //  ide.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       startActivity(ide);
       finish();*/

 //  ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,android.R.id.text1, friends_list);
//   lv.setAdapter(adapter);



   } catch (JSONException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     } catch (FacebookError e) {
       // TODO Auto-generated catch block
     e.printStackTrace();
 } 
 }
 });

请帮助我如何获得我/朋友的生日和个人资料照片。

0 个答案:

没有答案