Reputation: 145
Python beginner here - I'm trying to program in python so I can change our users' signature for our organization. I'm having trouble following this guide.
The code examples are clear but how to get started is not. I vaguely understand that I need to use oauth2 like here, and fully understand how to create a token under the developers console.
Can someone give me a code snippet to connect using oauth2
with "Fake Token" and retrieve everyone's account email and their signature settings? This would help me use other methods from the classes mentioned in the DOC.
Upvotes: 6
Views: 2181
Reputation: 6344
There are a few examples that demonstrate using python and assume that you have installed the following modules: gdata, oauth2client, and/or apiclient. Use these links to install them Google API Client Library for Python and Google Data Python Library.
There are samples spread across the API and developer site but these were the most helpful.
The documentation has a code snippet that shows how to modify a Signature using Python libs.
import gdata.apps.emailsettings.client
...
client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='yourdomain')
client.ClientLogin(email='adminUsername@yourdomain', password='adminPassword', source='your-apps')
client.UpdateSignature(username='liz', signature="Liz Jones - (+1) 619-555-5555" +
"Accounts Management, A&Z LTD.")
Here is an example of getting your Signature for your domain (thanks to this post)
credentials = get_credentials()
client = gdata.apps.emailsettings.client.EmailSettingsClient(domain='yourdomain.com')
client.auth_token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
val = client.RetrieveSignature(username="yourusername")
The next step is to get a list of all users for the domain and iterate over the list.
Upvotes: 3