0

I'm having trouble doing just about anything in OAuth2 using Python. I've gone through about 20 different iterations of example code from multiple sites and none of them work. Here is what I have in my file at this very moment but it doesn't compile. Any suggestions? Thanks in advance!

import requests
from requests_oauthlib import OAuth2Session
from requests.auth import HTTPBasicAuth
from oauthlib.oauth2 import BackendApplicationClient

client_id = "xxx"
client_secret = "yyy"
authorization_base_url = 'https://accounts.google.com/o/oauth2/auth'
token_url = 'https://accounts.google.com/o/oauth2/token'
project_id = 'zzz'
redirect_uri = "http://localhost"

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url=token_url, client_id=client_id,
    client_secret=client_secret)

1 Answer 1

1

You can use the Python Quickstart as reference as it's compatible with Python 2.6 or greater.

Don't forget, you need a local webserver to test this so it can connect to internet. You can use something like

python -m SimpleHTTPServer 8080
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.