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
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')
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')