如何通过gmail api从用户线程中仅检索文本片段?

问题描述 投票:0回答:1

我试图从gmail api的用户电子邮件中尽可能多地检索文本。我已经成功检索了线程列表ID,线程ID,历史ID以及来自线程即电子邮件的文本片段。我试图完成的只是从线程或电子邮件中检索一段文本,或者可能从电子邮件的线程中检索所有文本。这是我到目前为止的代码和结果

- (void)fetchThreads{

 self.output.text = @"\n Getting threads...";
//     NSString *threadID = @"15fb742b462acbdc";
//     NSString *threadID1 = @"15f56dc58e92f914";
//     NSString *messageID = @"0x600000453020";

     GTLRGmailQuery_UsersThreadsList *query = [GTLRGmailQuery_UsersThreadsList queryWithUserId:@"me"];


     query.q = @"in:drafts";
     query.userId = @"me";


 self.service.shouldFetchNextPages = true;
    NSLog(@"The number is 1");
 [self.service executeQuery:query

 delegate:self

 didFinishSelector:@selector(displayResultWithTicket2:finishedWithObject:error:)];

 }




- (void)displayResultWithTicket2:(GTLRServiceTicket *)ticket finishedWithObject:(GTLRGmail_ListThreadsResponse *)threadResponse
                           error:(NSError *)error {

    if (error == nil) {

        NSMutableString *threadString = [[NSMutableString alloc] init];

        if (threadResponse.threads.count > 0) {

            [threadString appendString:@"Labels:\n"];

            for (GTLRGmail_Thread *thread in threadResponse.threads) {
                [threadString appendFormat:@"\n This is message %@ \n", thread];

            }

        } else {

            [threadString appendString:@"No labels found."];
            NSLog(@"The eror is %@", error.localizedDescription);
        }

        self.output.text = threadString;

    } else {

        [self showAlert:@"Error" message:error.localizedDescription];

    }

}

结果:

This is message GTLRGmail_Thread 0x604000259200: {id:"15f500862dbcee7b" snippet:"Coffin of Ankhefenmut Author: John Smith Professor: Ms. Strum Course: Survey of Art in the Western World I, ARH170 Due Date: 10/24/17 The Ancient Egyptians are one of the worlds oldest civilizations" historyId:"2636014"} 

 This is message GTLRGmail_Thread 0x604000259470: {id:"15f02e206c54b910" snippet:"A Review of Alice Goffman's “On the Run” Alice Goffman's “On the Run” is a well-conducted sociological and ethnographical incite into the lives of young black youth during the “Tough on Crime”" historyId:"2636016"} 

 This is message GTLRGmail_Thread 0x60400024ec70: {id:"15ec4d1581e8bf30" snippet:" Introduction to Social Research - Ms. Wynn | Due 9/28/17 | 001261311 The Tearoom Trade Study Review The sociologist Laud Humphrey's conducted a very controversial study in the" historyId:"2406852"} 
objective-c xcode gmail-api
1个回答
0
投票

你必须在Objective-C上实现它。使用Users.messages.get,只需将“snippet”属性设置为“fields”参数即可。这将仅返回代码段响应。

来自Try-it的样本回应应用:

{
 "snippet": "Your script, testscript, has recently failed to finish successfully."
}
© www.soinside.com 2019 - 2024. All rights reserved.