2

我正在尝试修复我的脚本,该脚本使用新的 OAuth2 身份验证在 Google Apps 上设置邮件转发。我的目录 API 工作正常,但上周使用用户名/密码身份验证停止转发。

我已经根据此处的另一篇帖子(使用 Google Apps 服务帐户启用邮件转发)更新了我的代码,包括看起来与那里标记为“最终工作代码”的内容相同的内容,但无法找出问题所在。

进行身份验证时,我收到以下错误:

Traceback (most recent call last):
  File "./tmp.py", line 26, in <module>
    client.UpdateForwarding(username="chauvetp@hawkmail.newpaltz.edu",  enable=True, forward_to='sysadmin@newpaltz.edu', action='ARCHIVE')
  File "/usr/lib/python2.6/site-packages/gdata/apps/emailsettings/client.py", line 320, in update_forwarding
    return self.update(new_forwarding, **kwargs)
  File "/usr/lib/python2.6/site-packages/gdata/client.py", line 730, in update
    desired_class=entry.__class__, **kwargs)
  File "/usr/lib/python2.6/site-packages/gdata/client.py", line 307, in request
    response, Unauthorized)
gdata.client.Unauthorized: Unauthorized - Server responded with: 401, 

我的代码如下:

import gdata.gauth
import gdata.apps.emailsettings.client
from oauth2client.client import SignedJwtAssertionCredentials

service_account = My_Service_Account
adminEmail = My_Admin_Email
scope = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/'

keyfile = file(My_Key_Location,'rb')
key = keyfile.read()
keyfile.close()

credentials = SignedJwtAssertionCredentials(service_account, key, sub=My_Admin_Email, scope='https://apps-apis.google.com/a/feeds/emailsettings/2.0/')

auth = gdata.gauth.OAuth2Token(      
  credentials.client_id,#serviceEmail
  credentials.client_secret,#private key 
  scope='https://apps-apis.google.com/a/feeds/emailsettings/2.0/',
  access_token=credentials.access_token,
  refresh_token=credentials.refresh_token,
  user_agent=credentials.user_agent)
client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='MyDomain')
auth.authorize(client)

client.UpdateForwarding(username="TestAccount", enable=True, forward_to=DestinationAddress, action='ARCHIVE')

我会在上面引用的上一篇文章中添加评论,但我在这里的帐户是新的(它说我需要 50 声望才能发表评论)。对此的任何帮助将不胜感激!

4

0 回答 0