Reputation: 1062
I am currently using Gmail API to develop an application to read emails for specific information that the user gives me permission for. I am able to run it for my own inbox using the quickstart tutorial.
However, I am getting confused about how to run my application on a server, so that it keeps on taking user permission and running the application for each user monthly without any input.
Any leads in the right direction would be useful.
Upvotes: 0
Views: 460
Reputation: 116868
Assuming you are using this code Python Quickstart
Then you need to have a look at a few things about this code.
This code is designed as an installed application.
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
Which is why it says To learn how to create credentials for a desktop application,
This code is designed to run on the users machine. That is because it opens the consent screen in the browser of the machine its running on. If you tried to put it on a server it will not work as the user wont be able to access the consent screen if it tries to open on a server.
The second issue with this code is it is designed to be single user. When a user runs this code their consent is stored in the form of an access token and a refresh token in this file
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
So every time it runs its either going to run as the same user or you will need to remove the token.json and it will let you login as a different user. For this to work multi user you would need to set it up to create a new json file for each user rather than single user.
You need to figure out how to get the google api python client library to run on a server for multi user i have unfortunately never figured out if it even supports that.
Are you aware of the cost of verification of an app using Gmail scopes?
Upvotes: 1