Gmail OAuth Swift

253 views
Skip to first unread message

Daniel James

unread,
Jul 21, 2020, 9:23:47 AM7/21/20
to Google APIs Client Library for Objective-C
I'm trying to get the messages list from gmail with Google API. So far I have implemented the AppAuth process with
"https://github.com/openid/AppAuth-iOS" and I have my token response.

What I am trying to do now is 

func listInboxMessages() {
let gmailService = GTLRGmailService.init()

let listQuery = GTLRGmailQuery_UsersMessagesList.query(withUserId: "me")
listQuery.labelIds = ["INBOX"]

// let authorizer = GIDSignIn.sharedInstance()?.currentUser?.authentication?.fetcherAuthorizer()
// gmailService.authorizer = authorizer

gmailService.executeQuery(listQuery) { (ticket, response, error) in
    if response != nil {
        print("Response: ")
        print(response)
    } else {
        print("Error: ")
        print(error)
    }
}
But the commented lines comes from GoogleSign In. Which is not present in my project. Withouth them I
 "Expected OAuth 2 access token, login cookie or other valid authentication credential"
How can I obtain the messages list (gmail) with my token? I'm also trying to study the official documentation or "https://github.com/google/google-api-objectivec-client-for-rest" but I can't find something helpful


thom...@google.com

unread,
Jul 21, 2020, 9:47:39 AM7/21/20
to Google APIs Client Library for Objective-C
Wiki also mentioned you can use https://github.com/google/GTMAppAuth to use AppAuth-iOS instead of GoogleSignin.  If you want to manually build up the integration, look at that project for bridging things over into an Authorizer to use the the GTMSessionFether used by GTLR.

TVL

Aniket Kumar Singh

unread,
Sep 12, 2020, 10:14:47 AM9/12/20
to Google APIs Client Library for Objective-C
Yup
Reply all
Reply to author
Forward
0 new messages