PyFoursquare: Python Library for Foursquare
-
Upload
marcel-caraciolo -
Category
Technology
-
view
5.949 -
download
3
description
Transcript of PyFoursquare: Python Library for Foursquare
Py
Marcel CaracioloCientist Chief, Orygens
@marcelcaraciolo / [email protected]://aimotion.blogspot.com
Python API interface for Foursquare
Saturday, January 28, 2012
First, What is Foursquare ?
A location based social network
Share with your friends where you are and and what to do there
Discover new places and Share reviews
http://www.foursquare.comSaturday, January 28, 2012
Foursquare API
Foursquare provides an API to create new apps for using their data
It has several components to access: User Data, Checkins Data, Reviews, Venues, etc.
Using REST API and Oauth
Saturday, January 28, 2012
PyFoursquare
Created at 2010 as a private project for my master thesis.
Be a wrapper for interfacing with Foursquare API in Python
There are many others but they are not updated
https://github.com/marcelcaraciolo/foursquare
Saturday, January 28, 2012
Tweepy
A Python library for accessing the Twitter API.
Easy-To-Use API and Models-based oriented
Each entity of Twitter is represented as a Model
import tweepy
public_tweets = tweepy.api.public_timeline()for tweet in public_tweets: print tweet.text
Saturday, January 28, 2012
PyFoursquare
The idea was to be a Tweepy-based Architecture for Foursquare
It is on version 0.0.12
Only supports Places Details, Tips, Users and Places Searchclass Model(object):
def __init__(self, api=None): self._api = api
def __getstate__(self): # pickle pickle = dict(self.__dict__) try: del pickle['_api'] # do not pickle the API reference except KeyError: pass return pickle
@classmethod def parse(cls, api, json): """Parse a JSON object into a model instance.""" raise NotImplementedError
class Tip(Model): @classmethod def parse(cls, api, json): tip = cls(api) for key, value in json.items(): if key == 'done' or key == 'todo': setattr(tip, key, value['count']) elif key == 'user': setattr(tip, key, User.parse(api, value))
else: setattr(tip, key, value) return tip
def __repr__(self): return self.text[:10].encode('utf-8')
Saturday, January 28, 2012
PyFoursquare
easy_install pyfoursquare
>>> import pyfoursquare
Step 1 : Install the PyFoursquare
Saturday, January 28, 2012
PyFoursquare
Step 2 : Create your Developer Account and App
https://foursquare.com/oauth/
Saturday, January 28, 2012
PyFoursquare
Step 3 : Authenticate your Appimport foursquare
#
# 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
Saturday, January 28, 2012
PyFoursquare
Step 4 : After Authorizing play with the API, yeah!
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
Saturday, January 28, 2012
Release Plan
More Coverage tests in the API
Support for new entities: Photos, Checkins, etc.
More Examples and docs
MIT License and It is Open-Source!
https://github.com/marcelcaraciolo/foursquare
Fork and pull requests mandatory!
Saturday, January 28, 2012
Download your app at http://www.foursquare.com
Saturday, January 28, 2012
Py
Marcel CaracioloCientist Chief, Orygens
@marcelcaraciolo / [email protected]://aimotion.blogspot.com
Python API interface for Foursquare
Saturday, January 28, 2012