0

I would like to get the friendlist of the facebook using intent. Please let me know if there is any way to get the friends list of the facebook by using built in application of the device.

Thanks.

KevinM
  • 1,799
  • 4
  • 28
  • 58
GrIsHu
  • 29,068
  • 10
  • 64
  • 102

2 Answers2

0

You need to integrate the Android SDK into your app, here is the link to download the latest SDK. You then will have to have the user authenticate your app to access their information.

Here is sample code to do this

private SessionTracker mSessionTracker;
private Session mCurrentSession;

private void signInWithFacebook() {

    mSessionTracker = new SessionTracker(getBaseContext(), new StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
        }
    }, null, false);

    String applicationId = Utility.getMetadataApplicationId(getBaseContext());
    mCurrentSession = mSessionTracker.getSession();

    if (mCurrentSession == null || mCurrentSession.getState().isClosed()) {
        mSessionTracker.setSession(null);
        Session session = new Session.Builder(getBaseContext()).setApplicationId(applicationId).build();
        Session.setActiveSession(session);
        mCurrentSession = session;
    }

    if (!mCurrentSession.isOpened()) {
        Session.OpenRequest openRequest = null;
        openRequest = new Session.OpenRequest(SignUpChoices.this);

        if (openRequest != null) {
            openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
            openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location"));
            openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

            mCurrentSession.openForRead(openRequest);

            Request.executeMeRequestAsync(mCurrentSession, new Request.GraphUserCallback() {

              // callback after Graph API response with user object
              @Override
              public void onCompleted(GraphUser user, Response response) {
                  Log.w("myConsultant", user.getId() + " " + user.getName() + " " + user.getInnerJSONObject());
              }
          });
        }
    }
}

One you have a user that has approved your app you can perform other Request about their information. friends info example

Community
  • 1
  • 1
KevinM
  • 1,799
  • 4
  • 28
  • 58
  • Thanks for responding but i want to achieve it using the intent as i have mentioned in my question. Please checkout the answer for which i have found a solution. – GrIsHu Jan 03 '13 at 04:45
-1

Finally i found a way to get the friendlist of the Facebook using Intent.

Intent m_fb=getOpenFacebookIntent(m_context);           
            startActivity(m_fb);

public static Intent getOpenFacebookIntent(Context context) {  
       try {  
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
              return new Intent(Intent.ACTION_VIEW,Uri.parse("fb://profile/<user_id>/fans"));           
       } catch (Exception e) {  
        return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/abc.xyz"));  
       }  
    }

You can use Official Facebook App with Intent listed HERE.

GrIsHu
  • 29,068
  • 10
  • 64
  • 102