我想用意向獲得facebook的好友列表。 請讓我知道是否有任何方式通過使用設備的內置應用程序獲取Facebook的朋友列表。如何在Android中使用Intent獲取Facebook Friendlist?
謝謝。
我想用意向獲得facebook的好友列表。 請讓我知道是否有任何方式通過使用設備的內置應用程序獲取Facebook的朋友列表。如何在Android中使用Intent獲取Facebook Friendlist?
謝謝。
最後,我找到了一種方法,使用Intent
來獲得Facebook的friendlist
。
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。
您需要將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
感謝您的迴應,但我想實現它使用的意圖,因爲我已經在我的問題中提到。請檢查我找到解決方案的答案。 – GrIsHu