Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a message to be unread/read using Gmail API using objective-C SDK?

I wrote the following function to modify the message by 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's an error saying the id (which I think means the query.identifier I set) is an unknown field name. I also tried to set 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?

like image 244
yuklai Avatar asked Jun 30 '14 02:06

yuklai


2 Answers

Hi fatshu and Andy,

while we work on fixing the root issue, doing this should temporarily make it work:

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

(right before your call to executeQuery).

Cheers and sorry for the inconvenience,

Jorge

EDIT: As user3377170 correctly points out, the bug is now fixed and the workaround isn't necessary anymore.

like image 149
jcanizales Avatar answered Oct 03 '22 06:10

jcanizales


This was a bug; it is now fixed.

It is no longer necessary to use the strict = false workaround that was mentioned here.

like image 30
Brandon Jewett-Hall Avatar answered Oct 03 '22 08:10

Brandon Jewett-Hall