1
在API控制檯中的[email protected]
下我創建了一個項目,並且我成功地使用了服務帳戶Analytics API
和Search Console API
服務。現在我已經啓用了Gmail V1
API和運行此代碼:具有服務帳戶的Gmail API
gmail_scopes = [
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.compose",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.send",
"https://www.googleapis.com/auth/gmail.readonly"
]
gmail = Google::Apis::GmailV1::GmailService.new
gmail.authorization = Google::Auth.get_application_default(gmail_scopes)
這是相同的代碼(當然,不同的範圍),我使用授權分析和搜索控制檯API。
但是我得到BAD REQUEST
Failed Precondition
錯誤,當我運行此:
gmail.get_user_profile("[email protected]")
一些谷歌搜索告訴我,是因爲API試圖訪問的serviceaccount電子郵件地址不存在的收件箱中,並且在initiatlization過程中我需要包含[email protected]
以便API服務將使用該收件箱。
我該怎麼做?
我已經試過以下「...」始終是電子郵件地址
gmail.authorization = Google::Auth.get_application_default(gmail_scopes, username: '...')
gmail.authorization = Google::Auth.get_application_default(gmail_scopes, {username: '...'})
gmail.authorization.username = '...'