I'm trying to send a gmail message in Swift using the GoogleAPIClientForREST and GTMOAuth2 libraries but I'm getting the aforementioned error.
Here's my code:
let message = GTLRGmail_Message()
message.raw = "test"
let query = GTLRGmailQuery_UsersMessagesSend.query(withObject: message, userId: "[email protected]", uploadParameters: nil)
let gmailService = GTLRGmailService()
let auth = GTMOAuth2Authentication()
auth.clientID = gmailClientID
gmailService.authorizer = auth
gmailService.executeQuery(query) { ticket, object, error in
print(ticket)
print(object)
print(error)
}
and here's the error:
Optional(Error Domain=com.google.GTMOAuth2 Code=-1001 "(null)" UserInfo={request=<NSMutableURLRequest: 0x600000016ed0> { URL: https://www.googleapis.com/gmail/v1/users/example%40gmail.com/messages/send?prettyPrint=false }})
Notes:
- I used "[email protected]" for sake of asking the question, I'm using a real email in my app.
- I followed all the basic steps in Google's tutorial
Make sure that you've integrated
GTMOAuth2properly into your app by following this tutorial. Be sure to register the Platform asOtherand NOTiOSotherwise you'll get "invalid_client" error when authenticating.You may also check the given solution on this thread.