Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, redirect
- import requests
- import json
- app = Flask(__name__)
- CLIENT_ID = 'ENTER CLIENT ID HERE'
- CLIENT_SECRET = 'ENTER CLIENT SECRET HERE'
- CODE = 'ENTER CODE HERE'
- REFRESH_TOKEN = 'ENTER REFRESH_TOKEN HERE'
- @app.route('/get-auth-code')
- def get_oauth_code():
- CLIENT_ID = 'ENTER CLIENT ID HERE' # update the client Id
- url = f'https://app.hubspot.com/oauth/authorize?client_id={CLIENT_ID}&scope=contacts&redirect_uri=https://127.0.0.1:5000'
- return redirect(url, code=302)
- @app.route('/get-access-token')
- def get_access_token():
- data = {
- 'grant_type' : 'authorization_code',
- 'client_id' : CLIENT_ID,
- 'client_secret' : CLIENT_SECRET,
- 'scope' : 'contacts',
- 'redirect_uri' : 'https://127.0.0.1:5000',
- 'code' : CODE
- }
- headers = {'Content-Type' : 'application/x-www-form-urlencoded;charset=utf-8'}
- url = 'https://api.hubapi.com/oauth/v1/token'
- resp = requests.post(url, data = data, headers = headers)
- return resp.json()
- @app.route('/refresh-access-token')
- def refresh_access_token():
- data = {
- 'grant_type' : 'refresh_token',
- 'client_id' : CLIENT_ID,
- 'client_secret' : CLIENT_SECRET,
- 'refresh_token' : REFRESH_TOKEN
- }
- headers = {'Content-Type' : 'application/x-www-form-urlencoded;charset=utf-8'}
- url = 'https://api.hubapi.com/oauth/v1/token'
- resp = requests.post(url, data = data, headers = headers)
- return resp.json()
- if __name__ == '__main__':
- app.run(debug=True)
Add Comment
Please, Sign In to add comment