Gmail API | Request a Message

  1. 2 years ago
    Edited last year by niutech

    Ok so I have been playing around with the Gmail API. Now as you may know theres no official API Client for swift so Im using the objective-C client and using swift to work with it.

    So far I have been able to retrieve labels and an array of messages(which are just the message ID's). Now that I have the message ID's I want to actually grab the message that correspond to those ID's but I have ran into trouble I have the method that I need to get the message but it doesn't take any parameters.

    let query = GTLQueryGmail.queryForUsersMessagesGet() as! GTLQueryProtocol
    service.executeQuery(query, delegate: self, didFinishSelector: "displayResultWithTicket:finishedWithObject:error:")

    Now i asked over on StackOverflow but the only answer I got was really not useful to me he stated this:

    "You need to put the parameters into an attribute of the returned query object:"

    Does anyone know how to do what I'm doing or know what this guy means?

  2. last year

    niutech

    22 Jan 2016 Administrator

    From GTLQueryGmail.h:

    // Method: gmail.users.messages.get
    // Gets the specified message.
    //  Optional:
    //   format: The format to return the message in. (Default kGTLGmailFormatFull)
    //      kGTLGmailFormatFull: "full"
    //      kGTLGmailFormatMetadata: "metadata"
    //      kGTLGmailFormatMinimal: "minimal"
    //      kGTLGmailFormatRaw: "raw"
    //   identifier: The ID of the message to retrieve.
    //   metadataHeaders: When given and format is METADATA, only include headers
    //     specified.
    //   userId: The user's email address. The special value me can be used to
    //     indicate the authenticated user. (Default me)
    //  Authorization scope(s):
    //   kGTLAuthScopeGmail
    //   kGTLAuthScopeGmailModify
    //   kGTLAuthScopeGmailReadonly
    // Fetches a GTLGmailMessage.
    + (instancetype)queryForUsersMessagesGet;

    So you should add query parameters like:

    query.urlQueryParameters = ["identifier": id]

or Sign Up to reply!