6

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
JuniorPenguin
  • 163
  • 10
  • Your post is difficult to answer because it is unclear what you've tried and has multiple components. It sounds like there are two questions how do you use the API to change your own signature and how do you get a user's token via oauth2 - Oauth2 is a method to get a token for a user to send API requests on their behalf. Please update this question with information on what you've tried and what errors you've encountered. – osowskit Sep 07 '15 at 18:49
  • My question basically states that docs mentioned in my post didn't help me get started (I need lot of hand holding since I'm a beginner.) Would someone please help me get started by providing a sample code that will connect to gmail using oauth, and enumerate users list in order to change their signatures. – JuniorPenguin Sep 09 '15 at 16:40

1 Answers1

3

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.

  1. Quickstart for Python provides a way to get credentials and uses the api-client module
  2. 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.")
    
  3. 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.

Community
  • 1
  • 1
osowskit
  • 5,904
  • 2
  • 29
  • 38