问题描述
我想使用gdata的库一个谷歌帐户的名字和姓氏。我有身份验证令牌(我把它从Android设备 - 它发送到我的Java的servlet那么应该增加插入到一个MySQL数据库与第一,最后显示名称和provider_uid(provider_uid是的 .. ))。
I want to get first and last name of a google account using gdata library. I have the auth token(I take it from android device - send it to my java servlet- then should add an insert into a mysql db with first, last, display name and provider_uid(provider_uid is the form of https://www.google.com/accounts/o8/id?id=AItOawmyn...)).
我用的联系人供稿像这样(没有成功):
I used Contacts feed like this(without success):
public String tryGoogleAuthentication(String auth_token){
ContactsService contactsService = new ContactsService("...");
contactsService.setUserToken(auth_token);
//contactsService.setAuthSubToken(auth_token);
ContactFeed feed = null;
try {
feed = contactsService.getFeed(new URL("https://www.google.com/m8/feeds/contacts/" + "[email protected]" + "/full?max-results=10000"), ContactFeed.class);
} catch (IOException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
} catch (ServiceException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
} catch (NullPointerException e) {
e.printStackTrace();
return CONST.GOOGLE_AUTH_INVALID_TOKEN;
}
if (feed == null)
return "";
String externalId = feed.getId();
Person person = feed.getAuthors().get(0);
String email = person.getEmail();
String name = person.getName();
String nameLang = person.getNameLang();
String extensionLocalName = person.getExtensionLocalName();
String uri = person.getUri();
System.out.println("externalId: " + externalId);
System.out.println("email: " + email);
System.out.println("name: " + name);
System.out.println("nameLang: " + nameLang);
System.out.println("extension local name: " + extensionLocalName);
System.out.println("URI: " + uri);
System.out.println(feed.getSelf().getEntries().get(0).getTitle().getPlainText());
return CONST.STATUS_OK;
}
此外,
System.out.println("ID: " + feed.getSelf().getEntries().get(0).getId());
将输出:
ID: http://www.google.com/m8/feeds/contacts/someEmail%40gmail.com/base/c....
但我想是这样的:
but I want something like this:
https://www.google.com/accounts/o8/id?id=AItOawmyn...
我需要这个插入到现有数据基础。
I need this to insert into an existing data base.
请注意,我想要的信息只为帐户,而不是它的联系。
Please note that I want the info only for the account, not for it's contacts.
谢谢,
亚历
推荐答案
请看到这个的。问题是,我不能从Android采取的auth_token访问用户配置文件,因为它是一个客户端登录令牌和客户端登录不具有访问用户的个人资料范围。我综合android系统OAUTH登录如并与令牌返回,我可以访问用户的个人资料。
Please see this answer from google groups for resolution. The problem is that I cannot access user profile with the auth_token taken from the android because it's a Client Login token, and Client Login does not have a scope for accessing user's profile. I integrated OAUTH login in android like this and with the token returned, I can access user's profile.
亚历克斯。
这篇关于GDATA:获取帐号(个体经营联系人)的名字和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!