Your SlideShare is downloading. ×
PyFoursquare: Python Library for Foursquare
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

PyFoursquare: Python Library for Foursquare

5,435
views

Published on

Lighting Talk given at XVIII Python Local group meeting Pernambuco - 28.01.2012

Lighting Talk given at XVIII Python Local group meeting Pernambuco - 28.01.2012

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,435
On Slideshare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Py Python API interface for Foursquare Marcel Caraciolo Cientist Chief, Orygens @marcelcaraciolo / marcel@orygens.com http://aimotion.blogspot.comSaturday, January 28, 2012
  • 2. 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
  • 3. 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 OauthSaturday, January 28, 2012
  • 4. 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/foursquareSaturday, January 28, 2012
  • 5. 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.textSaturday, January 28, 2012
  • 6. 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 Search class 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 class Tip(Model):         except KeyError:     @classmethod             pass     def parse(cls, api, json):         return pickle         tip = cls(api)         for key, value in json.items():     @classmethod             if key == done or key == todo:     def parse(cls, api, json):                 setattr(tip, key, value[count])         """Parse a JSON object into a model instance."""             elif key == user:                 setattr(tip, key, User.parse(api, value))         raise NotImplementedError             else:                 setattr(tip, key, value)         return tip     def __repr__(self):         return self.text[:10].encode(utf-8)Saturday, January 28, 2012
  • 7. PyFoursquare Step 1 : Install the PyFoursquare easy_install pyfoursquare >>> import pyfoursquareSaturday, January 28, 2012
  • 8. PyFoursquare Step 2 : Create your Developer Account and App https://foursquare.com/oauth/Saturday, January 28, 2012
  • 9. PyFoursquare Step 3 : Authenticate your App import foursquare # # This mode of authentication is the required one for Foursquare # The client id and client secret can be found on your applications 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_tokenSaturday, January 28, 2012
  • 10. 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].nameSaturday, January 28, 2012
  • 11. 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! Fork and pull requests mandatory! https://github.com/marcelcaraciolo/foursquareSaturday, January 28, 2012
  • 12. Download your app at http://www.foursquare.comSaturday, January 28, 2012
  • 13. Py Python API interface for Foursquare Marcel Caraciolo Cientist Chief, Orygens @marcelcaraciolo / marcel@orygens.com http://aimotion.blogspot.comSaturday, January 28, 2012