Initial settings when using the foursquare API in python

Preparation in the browser

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.

Preparation in development environment

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)

Reference URL

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

Initial settings when using the foursquare API in python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Tweet using the Twitter API in Python
Try using the BitFlyer Ligntning API in Python
Try using the DropBox Core API in Python
Using the National Diet Library Search API in Python
Getting the arXiv API in Python
Precautions when using pit in Python
Hit the Sesami API in Python
Hit the web API in Python
Access the Twitter API in Python
When using regular expressions in Python
Solve the Japanese problem when using the CSV module in Python.
Mouse operation using Windows API in Python
Get Youtube data in Python using Youtube Data API
Try hitting the YouTube API in Python
Regularly upload files to Google Drive using the Google Drive API in Python
[SEO] Flow / sample code when using Google Analytics API in Python
Notify using Notification Center when the execution environment is macOS in Python
A useful note when using Python for the first time in a while
Get image URL using Flickr API in Python
Tips for hitting the ATND API in Python
Let's judge emotions using Emotion API in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Hit the Firebase Dynamic Links API in Python
Try using ChatWork API and Qiita API in Python
Evernote API in Python
C API in Python 3
To automatically send an email with an attachment using the Gmail API in Python
Continue to retrieve tweets containing specific keywords using the Streaming API in Python
Initial settings for using Python3.8 and pip on CentOS8
Upload JPG file using Google Drive API in Python
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Determine the threshold using the P tile method in python
Get LEAD data using Marketo's REST API in Python
Send and receive Gmail via the Gmail API using Python
OpenVINO using Inference Engine Python API in PC environment
How to exit when using Python in Terminal (Mac)
Using the LibreOffice app in Python (1) Where are the macros?
A little bit from Python using the Jenkins API
I checked the reference speed when using python list, dictionary, and set type in.
Download the file in Python
Find the difference in Python
Try using the Twitter API
DEBUG settings when using Django
Try using the Twitter API
Attention when os.mkdir in Python
Try using the PeeringDB 2.0 API
Blender Python API in Houdini (Python 3)
Use configparser when using API
Call the API with python3.
Translate using googletrans in Python
Using Python mode in Processing
Get your heart rate from the fitbit API in Python!
Master the type in Python? (When should type check be done)
A memo when creating a directed graph using Graphviz in Python
Predict gender from name using Gender API and Pykakasi in Python
Things to keep in mind when using Python with AtCoder
[Python] I tried collecting data using the API of wikipedia
Scripts that can be used when using bottle in Python