我想使用intent获取facebook的好友列表。 如果有任何方法可以通过使用该设备的内置应用程序获取Facebook的朋友列表,请告诉我。
感谢。
答案 0 :(得分:0)
您需要将Android SDK集成到您的应用here is the link to download the latest 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());
}
});
}
}
}
如果您的用户已批准您的应用,则可以执行其他有关其信息的请求。 friends info example
答案 1 :(得分:-1)
最后,我找到了一种使用friendlist
获取Facebook 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")); } }
您可以使用官方Facebook应用程序列出HERE的意图。