1
votes

My requirement is i need add image signature to the Gmail users dynamically.

FYI: The following is the process i followed

  1. created project in google console

  2. created Oauth Client ID in the following way

    Application Type: web

    Authorised JavaScript origins: http://localhost

    Authorised redirect URIs: http://localhost:3000

  3. downloaded as client_request.json

The code is given below

'''

 from apiclient import discovery

 from googleapiclient.discovery import build
 from googleapiclient import discovery
 from httplib2 import Http
 from oauth2client import file, client, tools
 from oauth2client.tools import argparser, run_flow
 args = argparser.parse_args()
 from oauth2client.file import Storage
 SCOPES = 'https://www.googleapis.com/auth/gmail.settings.basic'
 STORAGE = Storage('credentials.storage')
 credentials = STORAGE.get()
 creds =None
 args.noauth_local_webserver = True
 http = httplib2.Http()
 if not creds or creds.invalid:
   flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
   creds = tools.run_flow(flow, STORAGE,http=http)
 GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
 addresses = GMAIL.users().settings().sendAs().list(userId='me',
    fields='sendAs(isPrimary,sendAsEmail)').execute().get('sendAs')
for address in addresses:
 if address.get('isPrimary'):
    break
signature = {'signature':'<img src="https://server:8000/test.png" alt="asaa" width="100" height="100">'}

 rsp = GMAIL.users().settings().sendAs().patch(userId='me',
    sendAsEmail=address['sendAsEmail'], body=signature).execute()
 print("Signature changed to '%s'" % rsp['signature']) '''

I am stuck with 2 issues:

1) After i run the above code it is generating the following URL

https://accounts.google.com/o/oauth2/auth?client_id=123456789123-lkhipfqkk6g224bnf7n9sfdsdfsdss.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.settings.basic&access_type=offline&response_type=code

It is pointing to 8080 inspite specifying 3000 as redirection port

2) I am unable to generate dynamic URL which should be unique for every web request

Pls suggest the way forward

Thanks

1

1 Answers

0
votes

The redirect uri you are sending from redirect_uri=http://localhost:8080 must exactly match one of the redirect uris you have added in google developer console.

The error message tells you exactly which uri your application is sending as its redirect uri. You just need to add that.

It is pointing to 8080 in spite specifying 3000 as redirection port

You only specified in Google developer console that you will be sending from 3000 but your application appears to be sending from 8080.

Solution: add http://localhost:8080 to google developer console as a valid redirect uri or change your application to be sending from http://localhost:3000 which you have added to google developer console.