How to set up a read / read message using the Gmail API using the objective-C SDK?

I wrote the following function to modify the message, marking it unread:

- (void)modifyMessageWithId:(NSString *)gmailMessageId { __block GTLQueryGmail *query; query = [GTLQueryGmail queryForUsersMessagesModify]; query.identifier = gmailMessageId; query.addLabelIds = @[@"UNREAD"]; [self.gmailService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLGmailMessage *result, NSError *error) { // Check result here }]; } 

Then I checked the result and there is an error indicating id (which I think means query.identifier I) is an unknown field name. I also tried setting query.messageId instead and got a similar error:

(lldb) po error

Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "The operation couldn't be completed. (Unknown field name: id)" UserInfo=0xdd37e70 {error=Unknown field name: id, GTLStructuredError=GTLErrorObject 0xdd37cd0: {message:"Unknown field name: id" code:400 data:[1]}, NSLocalizedFailureReason=(Unknown field name: id)}

Any ideas how to do this?

+6
source share
4 answers

It was a mistake; now it is fixed.

You no longer have to use the string = false workaround mentioned here .

+1
source

Hi Fatsu and Andy,

while we are working on fixing the root problem, doing this should temporarily make it work:

 query.urlQueryParameters[@"strict"] = @"false"; 

(right before calling executeQuery).

Welcomes and regrets the inconvenience

Jorge

EDIT: As user3377170 correctly points out, the error has now been fixed and the workaround is no longer needed.

+2
source

There seems to be a bug in the Gmail API SDK.

+1
source

There is nothing wrong with the Gmail REST API. I was able to use the Google API Explorer to mark email as unread. The problem may be in their SDK for iOS.

So, there is a way to do this, but you may have to give up the iOS SDK and make a direct HTTP request to their REST API. Here's how you can do it:

Authorize your application through the OAuth stream , and then send a POST request:

 https://www.googleapis.com/gmail/v1/users/{SOME_EMAIL_ADDRESS}/messages/{MESSAGE_ID}/modify?key={YOUR_API_KEY} 

with the following POST request body:

 { "addLabelIds": ["UNREAD"] } 

See their API documentation on how to modify messages for more information. I would advise you to try using your Explorer API, as I did, to make sure that it works for you or not.

+1
source

Source: https://habr.com/ru/post/971515/


All Articles