0

我正在开发一个 iPhone 应用程序,在该应用程序中,我为用户提供了使用他/她的谷歌帐户登录的选项。现在,我希望通过 JSON 或 XML 获得该用户的 google 电子邮件 ID。我搜索了很多,但没有满意的结果。提前谢谢。

4

2 回答 2

0

您是否在他们的开发人员网站上使用 google api 检查了 oauth 授权? https://developers.google.com/accounts/docs/OAuth2

于 2012-06-01T07:38:05.480 回答
0

我想你可以从这个链接中找到一些东西.....希望这个链接对你有帮助..... http://code.google.com/p/gdata-objectivec-client/wiki/GDataObjCIntroductionhttps:/ /code.google.com/p/gdata-objectivec-client/ :)

想联系的时候写下面的代码....

GDataServiceGoogleContact *service = [self contactService];
        GDataServiceTicket *ticket;

        BOOL shouldShowDeleted = TRUE;
        const int kBuncha = 2000;

        NSURL *feedURL = [GDataServiceGoogleContact contactFeedURLForUserID:kGDataServiceDefaultUser];

        GDataQueryContact *query = [GDataQueryContact contactQueryWithFeedURL:feedURL];
        [query setShouldShowDeleted:shouldShowDeleted];
        [query setMaxResults:kBuncha];

        ticket = [service fetchFeedWithQuery:query
                                    delegate:self
                           didFinishSelector:@selector(contactsFetchTicket:finishedWithFeed:error:)];

        [self setContactFetchTicket:ticket];

下面的方法是 GmailAPI 委托方法...

- (GDataServiceGoogleContact *)contactService 
{
    static GDataServiceGoogleContact* service = nil;

    if (!service) {
        service = [[GDataServiceGoogleContact alloc] init];

        [service setShouldCacheResponseData:YES];
        [service setServiceShouldFollowNextLinks:YES];
    }

    [service setUserCredentialsWithUsername:txtEmail.text
                                   password:txtPass.text];

    return service;
}

之后你可以联系下面的代码......

for (int i = 0; i < [contacts count]; i++) {
        GDataEntryContact *contact = [contacts objectAtIndex:i];
        //        NSLog(@">>>>>>>>>>>>>>>> elementname contact :%@", [[[contact name] fullName] contentStringValue]);
        NSString *ContactName = [[[contact name] fullName] contentStringValue];
        GDataEmail *email = [[contact emailAddresses] objectAtIndex:0];
        //        NSLog(@">>>>>>>>>>>>>>>> Contact's email id :%@ contact name :%@", [email address], ContactName);
        NSString *ContactEmail = [email address];
}

希望这对你有帮助.... :)

于 2012-06-01T09:28:30.620 回答