Gmail API Users.messages:list [英] Gmail API Users.messages: list

查看:146
本文介绍了Gmail API Users.messages:list的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用电子邮件平台(Objective-C语言),并且想使用GTMHTTPFetcher和GTMOAuth2Authentication框架来获取一些邮件。我使用gmail API获取用户信息并获得适当的响应。

I'm working on email platform (in Objective-C language) and want to fetch some mails using GTMHTTPFetcher and GTMOAuth2Authentication frameworks. I'm using gmail APIs for getting userinfo and getting appropriate response.

我想要为用户的收件箱获取电子邮件类别;我正在考虑使用SYSTEM级别标签,例如 CATEGORY_SOCIAL ,用于社交, CATEGORY_PERSONAL 个人/小学等。

I want to fetch emails for the user's inbox with category; I'm thinking to use the SYSTEM level labels such as CATEGORY_SOCIAL for social, CATEGORY_PERSONAL For personal/primary, etc.

对于此功能,我使用以下GET API: https:// www.googleapis.com/gmail/v1/users/userId/messages 具有适当参数的API。我正在使用谷歌的尝试这个选项。
https://developers.google .com / gmail / api / v1 / reference / users / messages / list#try-it

For this functionality, I'm using following GET API: https://www.googleapis.com/gmail/v1/users/userId/messages API with proper parameters. I'm using google's try it out option for this. https://developers.google.com/gmail/api/v1/reference/users/messages/list#try-it

问题:我可以获取所有的messageID / threadID,但不能在google开发者控制台中获取labelID。我也从Objective-C代码中尝试过GET方法,但没有获得labelID。

Problem: I'm able to get all the messageIDs/threadIDs, but not able to get labelIDs in the google developer console. I've also tried this GET method from the Objective-C code, but didn't get the labelIDs.

我附加了Objective-C的代码片段你可以帮我解决这个问题吗?

I've attached the code snippet for the Objective-C code, Can you please help me out for this problem?

NSString *newAPIStr = @"";

newAPIStr = [NSString stringWithFormat:@"https://www.googleapis.com/gmail/v1/users/%@/messages?fields=messages(id,labelIds,threadId),nextPageToken&maxResults=%d",emailStr,maxResult];


NSURL *url = [NSURL URLWithString:newAPIStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"GET"];

GTMOAuth2Authentication *currentAuth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName clientID:kMyClientID clientSecret:kMyClientSecret];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
[myFetcher setAuthorizer:currentAuth];
[myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData, NSError *error) {
    if (error != nil) {
        // status code or network error
    } else {
        // succeeded
        NSDictionary* json = [NSJSONSerialization JSONObjectWithData:retrievedData options:kNilOptions error:&error];
        NSArray* messageArray =[json objectForKey:@"messages"];
        NSString *nextPageToken = [json objectForKey:@"nextPageToken"];
        for (NSDictionary *dictionary in messageArray) {
            [[EmailService instance].primaryMessages addObject:[dictionary objectForKey:@"id"]];
        }

        NSMutableArray *pArray = [[EmailService instance] primaryMessages];
        [[NSUserDefaults standardUserDefaults] setObject:pArray forKey: ALL_FUNNL];
        [[NSUserDefaults standardUserDefaults] setObject:nextPageToken forKey:@"PRIMARY_PAGE_TOKEN"];
        [[NSUserDefaults standardUserDefaults] synchronize];

        if([EmailService instance].primaryMessages.count < 5000)
            [self getPrimaryMessages:emailStr nextPageToken:nextPageToken numberOfMaxResult:100];
        else
            NSLog(@"----- Primary messages count > %d",pArray.count);
    }
}];}

获取输出如下:

{
messages:[
{
id:146da54fe3dc089e,
threadId:146da54fe3dc089e
},
{
id:146da41d9486982f,
threadId:146da41d9486982f
},
...
}

推荐答案

message.list()只返回消息,因为它是相当标准的REST行为,以保持响应小而快。如果您还需要获取有关邮件的更多信息(例如标签),则需要跟踪message.get(id = $ THAT_ID,format = MINIMAL),您可以使用批处理来调用许多内容消息并行。

message.list() only returns the ids of the messages, as is pretty standard REST behavior to keep the response small and fast. If you also need to get more info on the messages (such as the labels) you'd need to followup with something like message.get(id=$THAT_ID, format=MINIMAL), which you can call using batch to retrieve for many messages in parallel.

这篇关于Gmail API Users.messages:list的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆