gData: get account(self contact) first and last name

主宰稳场 提交于 2019-12-11 08:24:51

问题


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/" + "someEmail@gmail.com" + "/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;
}

Also,

System.out.println("ID: "  + feed.getSelf().getEntries().get(0).getId());

will output:

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.

Thanks,

Alex


回答1:


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.

Alex.



来源:https://stackoverflow.com/questions/9872495/gdata-get-accountself-contact-first-and-last-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!