我尝试使用Gmail API设置转发地址。
我在我的Gapps帐户上授权了API,但是我收到以下错误:
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}
以下是我的代码示例:
scope = [Gmail::AUTH_GMAIL_SETTINGS_BASIC]
attrs = {
json_key_io: File.open('lib/google/client_secret.json', 'r'),
scope: scope
}
auth = ::Google::Auth::ServiceAccountCredentials.make_creds(attrs)
impersonate_auth = auth.dup
impersonate_auth.sub ='paul@myd.com'
service = ::Google::Apis::GmailV1::GmailService.new
service.authorization = impersonate_auth
service.create_user_setting_forwarding_address(ue.email, auto_forwarding_request)
以下是我的Gapps上此服务的权限:
calendar
email
Email (Read/Write/Send) https://mail.google.com/
https://www.google.com/m8/feeds
https://www.googleapis.com/auth/gmail.settings.basic
https://www.googleapis.com/auth/gmail.settings.sharing
profile