1

上个月,我完成了一个使用 Python 的 GAE 应用程序,该应用程序广泛使用各种 Google API 来由 Google 管理员管理公司域内的 Google 资源。该应用程序已完成!!!,但本月谷歌宣布不再支持我目前正在实施的 EmailSettings API,电子邮件设置将迁移到 Gmail API;到目前为止,他们已经迁移了一些设置(即作为别名发送、转发、假期响应者和签名)。在 google 整理的迁移文档中,他们指出了两个 API 之间的主要区别以及关于如何迁移它的一些模糊的参考。无论如何,我目前正在尝试实施新的 API 以使用服务帐户修改发送方式设置。这是我为服务帐户创建服务的方式(再次,

scopes = ['https://mail.google.com/', 'https://www.googleapis.com/auth/gmail.settings.basic', 'https://www.googleapis.com/auth/gmail.settings.sharing']

email = "username@domain.bla"
credentials = oauth2.service_account.build_credentials(scope=scopes, user=me)       
http = httplib2.Http()
credentials.authorize(http)
service = google_api_helper.build("gmail", "v1", credentials)    
body = {'emailAddress':'anotheruser@domain.bla'}

service_2.users().settings().updateAutoForwarding(userId="me", body=body).execute()  

在这个特定的示例中,我正在尝试更新 AutoForwarding 设置,但它与某些 send-as 设置的场景和错误相同。我遇到的问题如下;对于谷歌所说的“精细设置”,我需要使用范围:' https://www.googleapis.com/auth/gmail.settings.sharing ',它需要创建一个服务帐户才能工作。

每当我尝试使用它时,我都会收到 500 错误消息:

HttpError:https://www.googleapis.com/gmail/v1/users/me/settings/autoForwarding?alt=json 返回“后端错误”>

如果我正在验证对服务帐户的域范围访问,为什么我会收到此错误,这是 API 错误还是我当前正在实施 oauth2 身份验证的方式?我尝试了几种实现都没有成功:

使用应用程序默认身份验证:

credentials = GoogleCredentials.get_application_default()
httpauth = credentials.authorize(Http())
service = build("gmail", "v1", http=http_auth)
aliases_2 = service.users().settings().sendAs().list(userId="username@domain.bla").execute()

使用更新的 oauth2client 库并通过本地 json 文件:

 credentials_new = ServiceAccountCredentials.from_json_keyfile_name("app/service_account_key.json", scopes)
 delegated_credentials = credentials_new.create_delegated(sub="username@domain.bla")
 http_auth = delegated_credentials.authorize(Http())
 service = build("gmail", "v1", http=http_auth) 

使用过时的 oauth2client 库并使用该库的新实现不再支持的 SignedJwtAssertionCredentials 函数:

credentials = SignedJwtAssertionCredentials(str(settings['oauth2_service_account']['client_email']).encode('utf-8'), settings['oauth2_service_account']['private_key'], scope=scopes, sub="username@domain.bla")
auth2token = OAuth2TokenFromCredentials(credentials) 
# With this implementation i was able to provide the google admin account which is supposed to have super admin access to the "sub" parameter, this used to work for the EmailSettings API, but for this new implementation you need to pass the email of the user you are trying to gain access to.
# build service
# call API

通过所有 3 个实现,我能够调用基本范围,但是每当我尝试对 settings.sharing 范围内的任何设置进行任何更改时,我都会收到后端错误消息。这让我发疯,我刚刚完成了这个应用程序!!!!如果您有任何想法或以前遇到过这个问题,请告诉我!!!!!!!...

4

1 回答 1

0

更新:截至 2016 年 8 月 11 日,此问题应已修复。

截至 2016 年 7 月 27 日,授权后端存在导致此错误的错误,尽管它似乎只影响某些域/用户。我们正在努力修复。请在此问题上加注星标以获取更新。

于 2016-07-27T16:25:18.540 回答