gpt4 book ai didi

android - 在带有 Parse.com 后端的 Android 中使用 Twitters API

转载 作者:行者123 更新时间:2023-11-29 21:10:09 25 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序上使用 Parse.com 来通过 Twitter 对我的用户进行身份验证。

基本上,我有一个“使用 Twitter 注册”按钮。当用户按下这个按钮时,Twitter 对话框打开,他就注册了。下面是 Register With Twitter 按钮的 onClick() 函数:

public void registerTwitter(View view)
{
ParseTwitterUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
//do something else, User quit the dialog
}
else if (user.isNew())
{
Intent i=new Intent(getApplicationContext(),Welcome.class);
startActivity(i);
}
else
{
//User already exists, do something else
}
}
});
}

在这里,代码可以正常工作,并且在后面按预期创建了一个 ParseUser。然而,问题是:如何从 Twitter API 获取其他公共(public)数据以添加到我的 ParseUser 对象中?喜欢名字、姓氏、图像、电子邮件等?

我在后端得到的只是“用户名”字段中的一个数字,以及来自 Twitter 的 authData 对象

任何帮助将不胜感激!谢谢

最佳答案

TwitterInfo twitterInfo = null;
Twitter twitter = ParseTwitterUtils.getTwitter();
String twitterUrl = "https://api.twitter.com/1.1/users/show.json?user_id=" + twitter.getUserId();

HttpUriRequest request = new HttpGet(twitterUrl);
twitter.signRequest(request);

HttpClient client = new DefaultHttpClient();

try
{
HttpResponse response = client.execute(request);
BufferedReader input = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

String result = input.readLine();
Log.d(TAG, "getTwitterInfo: result=" + result);

JSONObject JsonResponse = new JSONObject(result);

String profileImageUrl = JsonResponse.getString("profile_image_url");
String fullName = JsonResponse.getString("name");

twitterInfo = new TwitterInfo(fullName, profileImageUrl);

return twitterInfo;

}
catch(ClientProtocolException e)
{
throw new CamoPhotoException(e.getMessage());
}
catch(IOException e)
{
throw new CamoPhotoException(e.getMessage());

}
catch(JSONException e)
{
throw new CamoPhotoException(e.getMessage());

}

关于android - 在带有 Parse.com 后端的 Android 中使用 Twitters API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23186874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com