First, register on foursquare. Next, let's create an app with "Create New App" linked below. https://developer.foursquare.com/
To create an app, you need to set the following three.
If you just want to try it out, not an app that you publish on the web http://www.example.com/ It's okay at all.
After completing the settings, two values, Client id and Client secret, should be set. This will be used later.
First, install the foursquare wrapper.
pip install foursquare
Next, let's write the code to set up. Note that this code is python3, so in the case of python2, change ʻinput to
raw_input`.
setup.py
import foursquare
#Set the information of the created application
CLIENT_ID=#(Client id of the created app)
CLIENT_SECRET=#(Client secret of the created app)
REDIRECT_URI=#(Redirect URI of the created app)
#Create client object
client = foursquare.Foursquare(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_uri=REDIRECT_URI)
#App authentication
auth_uri = client.oauth.auth_url()
print(auth_uri)
#Displayed auth_Access uri from a browser and use the URI "?code=After ""#Enter the character string before ""
code=input("INPUT CODE:")
#Get an access token
access_token = client.oauth.get_token(code)
print(access_token)
#Set access token
client.set_access_token(access_token)
#Output your own user information as a trial
#Success if user information is displayed
user = client.users()
print(user)
Once you get an access token with the above code, you can use it repeatedly. Specifically, it looks like the following code.
test.py
import foursquare
#Information on the created app
ACCESS_TOKEN=#(Set ACCESS_TOKEN)
#Create client object
client = foursquare.Foursquare(access_token=ACCESS_TOKEN)
#Output your own user information as a trial
#Success if user information is displayed
user = client.users()
print(user)
mLewisLogic/foursquare https://github.com/mLewisLogic/foursquare What you can do with the foursquare API # 4sqdevjp http://qiita.com/koogawa/items/df92ec1c7eb750312b77 foursquareAPI - Connecting https://developer.foursquare.com/overview/auth
Recommended Posts