2017-03-03 57 views
0

我試圖使用GoogleAPIClientForRESTGTMOAuth2庫在Swift中發送Gmail郵件,但我收到上述錯誤。Swift Gmail API:嘗試發送郵件給出錯誤-1001

這裏是我的代碼:

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) 
    } 

和這裏的錯誤:

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 }}) 

注:

+0

您在調用url時可能有錯誤,請檢查其發送參數。 – vaibhav

+0

http://stackoverflow.com/q/19095861/665689指這 –

+0

@vaibhav爲什麼我的調用網址會出現錯誤?我沒有自己操縱任何網址,只使用了sdk。 – rigdonmr

回答

0

的所有基本步驟確保您已經按照此tutorial集成GTMOAuth2妥善到您的應用程序。請確保將平臺註冊爲Other而不是iOS,否則驗證時您會收到「invalid_client」錯誤。

您也可以檢查此thread上的給定解決方案。

+0

試過這個教程,然後嘗試克隆回購並使用它。兩者都沒有工作。我見過你發佈的其他問題。基本上說同樣的事情。該解決方案不適合我。 – rigdonmr

+0

通過使用'other'而不是'iOS',你必須包含你的密鑰,不是很安全...... – Nico

相關問題