如何在 Android 中获取 Twitter 用户个人资料?
如何通过 API 获取 Android 中经过身份验证的 Twitter 用户的用户名、电子邮件、位置、头像等?
我编写了下面的代码,但它总是在 twitter.showUser(twitter.getId());
返回 null
public User getUserInfo(Object accessToken)
{
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(mConsumer.getConsumerKey());
configurationBuilder.setOAuthConsumerSecret(mConsumer.getConsumerSecret());
twitter4j.Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance();
try
{
twitter.setOAuthAccessToken((AccessToken) accessToken);
return twitter.showUser(twitter.getId());
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
我发现了另一个问题 此处。人们表示无法通过 API 检索经过身份验证的 Twitter 用户的电子邮件地址。那么,其他信息(例如全名、头像、电话号码(如果有的话))怎么样?
How can I get the user name, email, location, avatar, etc., of an authenticated user of Twitter in Android via the API?
I wrote the code below, but it always returns null
at twitter.showUser(twitter.getId());
public User getUserInfo(Object accessToken)
{
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(mConsumer.getConsumerKey());
configurationBuilder.setOAuthConsumerSecret(mConsumer.getConsumerSecret());
twitter4j.Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance();
try
{
twitter.setOAuthAccessToken((AccessToken) accessToken);
return twitter.showUser(twitter.getId());
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
I found another question here. People said that unable to retrieve email address of authenticated user of Twitter via api. So, How about other information such as fullname, avatar, phone number (if have),...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论