You can upload the credentials for a single account in the data warehouse using the Remote API , which can be included in your app.yaml file:
builtins: - remote_api: on
Performing
remote_api_shell.py -s your_app_id.appspot.com
from the command line you will have access to a shell that can be run in your application environment. Before doing this, make sure your application is deployed (more about local development below) and make sure that the source for google-api-python-client enabled by pip installing and running enable-app-engine-project /path/to/project to add it to your App Engine project.
Once you get to the remote shell (after executing the remote command above), follow these steps:
from oauth2client.appengine import CredentialsModel from oauth2client.appengine import StorageByKeyName from oauth2client.client import OAuth2WebServerFlow from oauth2client.tools import run KEY_NAME = 'your_choice_here' CREDENTIALS_PROPERTY_NAME = 'credentials' SCOPE = 'https://www.googleapis.com/auth/drive' storage = StorageByKeyName(CredentialsModel, KEY_NAME, CREDENTIALS_PROPERTY_NAME) flow = OAuth2WebServerFlow( client_id=YOUR_CLIENT_ID, client_secret=YOUR_CLIENT_SECRET, scope=SCOPE) run(flow, storage)
NOTE. If you did not deploy the application with the google-api-python-client code, this will not succeed, since your application will not know how to make the same import data that you did on your local computer, for example. from oauth2client.appengine import CredentialsModel .
When run is called, your web browser will open and offer you to accept OAuth access for the client you specified with CLIENT_ID and CLIENT_SECRET , and upon successful completion, it will save the CredentialsModel instance in the repository of your_app_id.appspot.com deployed application and it will save it using KEY_NAME provided by you.
After that, any caller in your application, including your cron jobs, can access these credentials by doing
storage = StorageByKeyName(CredentialsModel, KEY_NAME, CREDENTIALS_PROPERTY_NAME) credentials = storage.get()
Local development:
If you want to test this locally, you can run the application locally via dev_appserver.py --port = PORT / path / to / project
and you can execute the same commands using the remote API shell and specify it in your local application:
remote_api_shell.py -s localhost:PORT
Once you are here, you can execute the same code that you did in the remote api shell, and in the same way, an instance of CredentialsModel will be stored in the data store of the local development server.
As stated above, if you do not have the correct google-api-python-client modules, this will not work.
EDIT: This is used to recommend using the interactive console at:
http:
but it was discovered that this did not work because socket did not work properly in the App Engine developer sandbox.