简体   繁体   中英

Use Google API from flask

I'm trying to build a Flask web application that should use some Google APIs (in particular Calendar). Users in the web application are already registered using a custom module, so Google is not used for login. In my application logged users should associate once their Google account to allow the use of APIs to handle their calendar. I've tried to follow the Google example , but it creates a local server which is accessible just locally and does not allows to have a link to embed into a button in a webpage.

I assume to have a structure like this:

@app.routes('/allow_calendar')
def allow():
    link = get_googleAuthLink();
    return render_template('page.html', link=link);

@app.routes(/'submit_token', methods=['POST'])
def submit_token():
     ....
     save token received in db

With a page like

<body>
     <a href={{ link}}>Click here to authorize</a>
     <form action="{{ url_for('submit_token') }}" method="POST">
          <input type="text" id="token">
          <input type="submit" value="Submit">
     </form>
</body>

Does anyone knows how to do this?

You may not want to use Google for Login (authentication openId connect) but you do want to access a users google calendar data which means that you will still need to use Google for (Authorization OAuth2)

The sample you are following Python quickstart is intended for use with command line application, this means you are creating installed credentials.

Complete the steps described in the rest of this page to create a simple Python command-line application that makes requests to the Drive API.

This code will open the web browser window for user authorization on the web server and not on the users machine. You should be using a web browser client and code designed for use with web applications .

Can we use google api without Google Workpace account?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM