使用Gmail ruby​​ API中的服务帐户添加转发地址

时间:2018-04-26 19:32:58

标签: ruby-on-rails gmail gmail-api

我尝试使用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 

0 个答案:

没有答案