我想编辑谷歌应用域中用户的签名。我打算使用服务帐户。服务帐户被委派给整个域。我使用 gmail API 来发送和检索电子邮件,但使用不同的 api 修改了签名。根据https://developers.google.com/admin-sdk/email-settings/这个 api 是我通过 Google Developer Console 启用的 Admin SDK。
我正在尝试使用库 gdata.apps.emailsettings.client (它不支持 Python 3.x)
建立凭据有效,但是当我尝试这样做时
gmail_client.RetrieveSignature(username)
我得到 gdata.client.Unauthorized: Unauthorized - 服务器响应:401。
# python 2.7 from macports
def setup_gmail_client_new_api():
client_email = '...3@developer.gserviceaccount.com'
key_path = 'VCI-EMAIL-INTEGRATION-f493528321ba.json'
sender = 'tim@vci.com.au'
API_scope = 'https://apps-apis.google.com/a/feeds/emailsettings/2.0/'
filename=key_path, scopes=API_scope)
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_path, scopes=API_scope)
return credentials
if __name__ == "__main__":
credentials = setup_gmail_client_new_api()
client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='vci.com.au')
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)
auth.authorize(client)
result = retrieve_sig(client,"tim")
print (result)
尝试检索签名:
gdata.client.Unauthorized: Unauthorized - Server responded with: 401,
服务帐户具有域范围的委派。在 google Apps 域安全控制面板(管理 API 客户端访问)中,服务 ID 具有“电子邮件设置(读/写) https://apps-apis.google.com/a/feeds/emailsettings/2.0/ ”的权限