[英]How to get twitter screen name in Firebase auth
Hi I am not sure how to get twitter screen name from getprovidersData() as it is returning a List and when I iterated the List it give data like嗨,我不知道如何从 getprovidersData() 获取 twitter 屏幕名称,因为它正在返回一个列表,当我迭代列表时,它给出的数据如下
D/Twitter Data:: com.google.android.gms.internal.zzafv@4f19ea4 D/Twitter Data:: com.google.android.gms.internal.zzafv@eb40d D/Twitter 数据:: com.google.android.gms.internal.zzafv@4f19ea4 D/Twitter 数据:: com.google.android.gms.internal.zzafv@eb40d
List proData = mFirebaseUser.getProviderData();
for (Object ui:proData
) {
Log.d("Twitter Data:",ui.toString());
}
How will I get twitter use screen name from that.我将如何从中获得 twitter 使用屏幕名称。
Thank you!谢谢!
This code is derived from the example provided in the documentation .此代码源自文档中提供的示例。 Please try running it after you have signed in with Twitter to see if the display name is the screen name you are expecting.请在使用 Twitter 登录后尝试运行它,以查看显示名称是否是您期望的屏幕名称。
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
for (UserInfo profile : user.getProviderData()) {
if (profile.getProviderId().equals(TwitterAuthProvider.PROVIDER_ID)) {
// UID specific to the provider
String uid = profile.getUid();
// Name, email address, and profile photo Url
String name = profile.getDisplayName();
String email = profile.getEmail();
Uri photoUrl = profile.getPhotoUrl();
Log.i("DEBUG", String.format("uid=%s name=%s email=%s url=%s",
uid, name, email, photoUrl));
}
}
}
You need 4 things to get twitter user details including screen_name.您需要 4 件事来获取 twitter 用户详细信息,包括 screen_name。
1 and 2 you can get from twitter app dashboard. 1 和 2 您可以从 twitter 应用仪表板获得。
3 and 4 will be given in signInSuccessWithAuthResult
callback function in authResult
object when a user successfully signed in using firebase auth.当用户使用 firebase auth 成功登录时,将在authResult
对象中的signInSuccessWithAuthResult
回调函数中给出 3 和 4。 These 4 should go in header request for GET api call -> https://api.twitter.com/1.1/account/verify_credentials.json这 4 个应该进入 GET api 调用的标头请求 -> https://api.twitter.com/1.1/account/verify_credentials.json
more info on this: https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials更多信息: https : //developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials
https://www.npmjs.com/package/twitter https://www.npmjs.com/package/twitter
或者只需在标题中使用您的 Bearer 调用https://api.twitter.com/2/users/$userID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.