Enable mail forwarding using a Google Apps Service Account

后端 未结 2 1826
北荒
北荒 2020-12-11 10:47

On April 20, 2015, several Google Apps APIs are being discontinued, including the Provisioning API(gdata).
In my Python scripts, I am using a Service Account and OAuth 2

相关标签:
2条回答
  • 2020-12-11 11:04

    There were a few things I needed to change to my last update in order for my code to work: I needed to use user_agent=credentials.user_agent, remove the client.additional_headers, and I used the client_id and client_secret from credentials instead of passing them in myself(not sure if that was a variable type issue).
    Final working code:

    credentials = SignedJwtAssertionCredentials(serviceEmail, key, sub=adminEmail, 
        scope='https://apps-apis.google.com/a/feeds/emailsettings/2.0/ '+'other scopes')
    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.co')
    auth.authorize(client)
    client.UpdateForwarding(username=username, enable=True, 
        forward_to=forwardTo, action='ARCHIVE')
    
    0 讨论(0)
  • 2020-12-11 11:20

    This should be the proper way to use the credentials object directly:

    import gdata.gauth
    
    credentials = SignedJwtAssertionCredentials(serviceEmail,
                                                key, 
                                                sub=adminEmail,
                                                scope=scopes)
    client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='mydomain.co')
    client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
    client.UpdateForwarding(username=username, enable=True, 
    forward_to=forwardTo, action='ARCHIVE')
    
    0 讨论(0)
提交回复
热议问题