Skip to content

Instantly share code, notes, and snippets.

@cmlawson
Created January 28, 2013 17:31
Show Gist options
  • Save cmlawson/4657413 to your computer and use it in GitHub Desktop.
Save cmlawson/4657413 to your computer and use it in GitHub Desktop.
Foursquare ID to Google Ref Get Google Reviews
require 'google_places'
require "foursquare2"
require "awesome_print"
require "google_plus"
API_KEY = "AIzaSyBTtzGadlCexbNTKtUxQWS65SRiewtpkgU"
@gpClient = GooglePlaces::Client.new(API_KEY)
GooglePlus.api_key = API_KEY
def foursquareToGoogle(fsqVenueId)
#Only get the closest Google Place. The right place may not exist.
foursquareVenue = #get the Venue fom the database
lat = foursquareVenue['location']['lat']
lng = foursquareVenue['location']['lng']
name = foursquareVenue(fsId)['name']
@gpReference = @gpClient.spots(lat, lng, :name => name, :rankby=>'distance')[0].reference
end
def getGoogleReviews(gpReference)
spot = @gpClient.spot(gpReference)
#person = GooglePlus::Person.get()
reviewArray = []
spot.reviews.each do |review|
#Filling user json
user_id = review.author_url.split(pattern='/')[3] #--> https://plus.google.com/user_id
person = GooglePlus::Person.get(user_id)
firstName = person.name.given_name
lastName = person.name.family_name
photo = person.image.url
user={ :id=>user_id,
:firstName=>firstName,
:lastName=>lastName,
:photo=>photo}
#Filling review json
id = '' #Not supplied by Google API
text = review.text
createdAt = review.time
rating = review.rating
reviewArray << { :id=>id,
:createdAt =>createdAt,
:text=>text,
:user =>user,
:rating=>rating}
end
return reviewArray
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment