Last active
December 20, 2015 09:59
-
-
Save marcomorain/6112356 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import requests | |
| import json | |
| import base64 | |
| from flask import Flask | |
| from flask import jsonify | |
| from flask import Response | |
| consumer_key = 'CONSUMER KEY FOR YOUR APP' | |
| consumer_secret = 'CONSUMER SECRET FOR YOUR APP' | |
| def get_token(key, secret): | |
| encoded = base64.standard_b64encode(key + ':' + secret) | |
| result = requests.post('https://api.twitter.com/oauth2/token', | |
| data = { | |
| 'grant_type': 'client_credentials' | |
| }, | |
| headers = { | |
| 'Authorization': 'Basic ' + encoded, | |
| 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' | |
| }) | |
| return result.json()['access_token'] | |
| token = get_token(consumer_key, consumer_secret) | |
| app = Flask(__name__) | |
| @app.route("/") | |
| def requst(): | |
| result = requests.get('https://api.twitter.com/1.1/statuses/user_timeline.json', | |
| params = { | |
| 'screen_name': 'swrve_inc', | |
| 'count': 2 | |
| }, | |
| headers = { | |
| 'Authorization': 'Bearer ' + token | |
| }) | |
| return Response(response=result.text, | |
| status=result.status_code, | |
| content_type='application/json') | |
| if __name__ == "__main__": | |
| app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment