Skip to content

Instantly share code, notes, and snippets.

@gracemcgrath
Created January 9, 2020 19:45
Show Gist options
  • Save gracemcgrath/345c144f1717bf896ed78ea08b999540 to your computer and use it in GitHub Desktop.
Save gracemcgrath/345c144f1717bf896ed78ea08b999540 to your computer and use it in GitHub Desktop.
Winterns2020: sample python API requests
from flask import Flask, render_template
import requests, json
app = Flask(__name__)
@app.route("/api-explorer", methods=['GET', 'POST'])
def makeRequest():
response = requests.post('https://api-ssl.bitly.com/v4/bitlinks', json={"long_url":"https://dev.bitly.com/v4/#operation/getBitlinksByGroup"},headers={'Authorization': 'Bearer <ACCESS_TOKEN>'})
print("My new bitlink: " + json.loads(response.text)["link"])
response2 = requests.get('https://api-ssl.bitly.com/v4/user', headers={'Authorization': '<ACCESS_TOKEN>'})
print("My group_guid response code: ", (response2.status_code))
return render_template('app.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment