2015-02-09 160 views
-2

我正在檢索Facebook朋友;你能建議如何從給定的代碼從Facebook中檢索。我是android新手。所以請幫助我做到這一點。我沒有從Facebook SDK獲得正確的指導方針。如何檢索朋友列表中的Facebook朋友?

代碼如下。

好友申請

import java.util.Arrays; 
import java.util.List; 

import com.facebook.Session; 
import com.facebook.Request; 

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.util.Log; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.facebook.HttpMethod; 
import com.facebook.Response; 
import com.facebook.Session; 
import com.facebook.SessionState; 
import com.facebook.UiLifecycleHelper; 
import com.facebook.model.GraphUser; 
import com.facebook.widget.LoginButton; 
import com.facebook.widget.LoginButton.UserInfoChangedCallback; 

public class MainActivity extends FragmentActivity { 

    private LoginButton loginBtn; 
    private UiLifecycleHelper uiHelper; 
    private ListView friendList; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     uiHelper = new UiLifecycleHelper(this, statusCallback); 
     uiHelper.onCreate(savedInstanceState); 

     setContentView(R.layout.activity_main); 
     friendList = (ListView) findViewById(R.id.friends_list); 

     loginBtn = (LoginButton) findViewById(R.id.fb_login_button); 
     loginBtn.setReadPermissions(Arrays.asList("email")); 
     loginBtn.setReadPermissions(Arrays.asList("user_friends")); 

//  final Session session = Session.getActiveSession(); 
     loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() { 
      @Override 
      public void onUserInfoFetched(GraphUser user) { 
       if (user != null) { 
//     new Request(
//       Session.getActiveSession(), 
//       "/me/friends", 
//       null, 
//       HttpMethod.GET, 
//       new Request.Callback() { 
//        public void onCompleted(Response response) { 
//         System.out.println("RESPONSE :- " + response.toString()); 
//         Log.i("DJ", "response; " + response.toString()); 
//        } 
//       }).executeAsync(); 
       } else { 

       } 
      } 
     }); 
    } 

    private Session.StatusCallback statusCallback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, 
       Exception exception) { 
      if (state.isOpened()) { 
       Log.d("MainActivity", "Facebook session opened."); 
      } else if (state.isClosed()) { 
       Log.d("MainActivity", "Facebook session closed."); 
      } 
     } 
    }; 

    @Override 
    public void onResume() { 
     super.onResume(); 
     uiHelper.onResume(); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     uiHelper.onPause(); 
    } 

    @Override 
    public void onDestroy() { 
     super.onDestroy(); 
     uiHelper.onDestroy(); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     uiHelper.onActivityResult(requestCode, resultCode, data); 
    } 

    @Override 
    public void onSaveInstanceState(Bundle savedState) { 
     super.onSaveInstanceState(savedState); 
     uiHelper.onSaveInstanceState(savedState); 
    } 


} 

回答

0

你需要在Facebook的先提交您的應用程序,你可以從那裏您生成應用程序ID控制檯找到它。因爲Facebook只允許一般 個人資料,將應用程序現在分配給您的訪問更多的許可令牌 您需要創建:

  1. 釋放鍵
  2. .apk文件
  3. 一個logo 1024 * 1024
  4. 在facebook apps控制檯填寫應用說明。

然後在3-7天內,他們將授權您的應用訪問您在提交時請求的其他許可。

+0

我已經做了所有的事情,我有我的fb應用程序ID和釋放密鑰 應用程序ID: - 1547076915541502 – 2015-02-09 06:08:53