0

我想使用意图获取 facebook 的好友列表。请让我知道是否有任何方法可以通过使用设备的内置应用程序来获取 facebook 的朋友列表。

谢谢。

4

2 回答 2

0

您需要将 Android SDK 集成到您的应用程序中,这里是下载最新 SDK 的链接。然后,您必须让用户验证您的应用程序才能访问他们的信息。

这是执行此操作的示例代码

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());
              }
          });
        }
    }
}

如果您的用户已批准您的应用程序,您可以对他们的信息执行其他请求。 朋友信息示例

于 2012-12-22T17:02:47.303 回答
-1

最后我找到了一种friendlist使用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"));  
       }  
    }

您可以使用此处列出的 Intent 的官方 Facebook 应用程序。

于 2012-12-24T05:09:07.263 回答