Giter Club home page Giter Club logo

foursquare's Introduction

PyFoursquare

PyFoursquare is a Python interface for the Foursquare API.

If you are looking for a complete foursquare-APIv2 reference, go to

<http://developer.foursquare.com/docs/>

How to Install it

After download the source code by:

easy_install pyfoursquare

or

https://github.com/marcelcaraciolo/foursquare/tarball/master

Just execute the command at the terminal:

$ python setup.py install

How to Use it

import pyfoursquare as foursquare
# == OAuth2 Authentication ==
#
# This mode of authentication is the required one for Foursquare

# The client id and client secret can be found on your application's Details
# page located at https://foursquare.com/oauth/
client_id = ""
client_secret = ""
callback = ''

auth = foursquare.OauthHandler(client_id, client_secret, callback)

#First Redirect the user who wish to authenticate to.
#It will be create the authorization url for your app
auth_url = auth.get_authorization_url()
print 'Please authorize: ' + auth_url

#If the user accepts, it will be redirected back
#to your registered REDIRECT_URI.
#It will give you a code as
#https://YOUR_REGISTERED_REDIRECT_URI/?code=CODE
code = raw_input('The code: ').strip()

#Now your server will make a request for
#the access token. You can save this
#for future access for your app for this user
access_token = auth.get_access_token(code)
print 'Your access token is ' + access_token

#Now let's create an API
api = foursquare.API(auth)

#Now you can access the Foursquare API!
result = api.venues_search(query='Burburinho', ll='-8.063542,-34.872891')

#You can acess as a Model
print dir(result[0])

#Access all its attributes
print result[0].name


"""
If you already have the access token for this user
you can go until lines  1- 13, and then get at
your database the access token for this user and
set the access token.

auth.set_access_token('ACCESS_TOKEN')

Now you can go on by the line 33.

"""

How to Use it with Django simple example

Download the pyfoursquare/examples folder.

Go to the the django/example folder.

You must have django installed at your machine. Django is a popular and powerful web framework written in Python.

http://www.djangoproject.com

Now, just execute the command at the terminal:

$ python manage.py syncdb

This command above will sync and create the tables using sqlite3.

Now edit the settings.py file and place your Developer's App Credentials:

FOURSQUARE_CLIENT_ID =  ''
FOURSQUARE_CLIENT_SECRET = ''
FOURSQUARE_CALLBACK = ''

Save it. Now run the command at the terminal:

$ python manage.py runserver

It will run the web app. This demo will demonstrate the authentication procedure and show the user name and photo.

Just open the browser and go to the url:

http://localhost:8000/

Enjoy it!

foursquare's People

Contributors

marcelcaraciolo avatar

Watchers

JT5D avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.