Wednesday, June 22, 2011

Yelp API Business Review Searches

Going along with the whole DataContractSerializer thing in .NET I thought I would share the class I use to deserialize business review searches with the Yelp API. As an added bonus, the Yelp API doesn't return any URL for a business so that you can easily navigate to the page to write a review for that business. It's easy to figure out though. The review URL uh, key, for a lack of better terms is just the business ID.

So here it goes, some VB.NET code to get businesses that match some common terms within a 1 mile(?) radius of a given latitude and longitude.



Public Sub getNearbyLocations(ByVal myLatitude As Long, ByVal myLongitude As Long)
If gps_allowed = True Then
myThrobber.Visibility = Visibility.Visible
myWebClient = New WebClient()
myWebClient.OpenReadAsync(New Uri("http://api.yelp.com/business_review_search?term=food%20bars%20pizza%20bar%20diner%20bar&lat=" & myLatitude & "&long=" & myLongitude & "&radius=1&limit=20&ywsid=YOURYELPAPIKEY"))
AddHandler myWebClient.OpenReadCompleted, AddressOf gotJson
Else
MessageBox.Show("You need to allow this application to use the GPS in the settings panel to use this function!")
End If
End Sub

Private Sub gotJson(ByVal sender As Object, ByVal e As OpenReadCompletedEventArgs)
For Each businessObject As yelpBusiness In placesMainPanel.Children
businessObject = Nothing
Next

placesMainPanel.Children.Clear()

Dim sr As New StreamReader(e.Result)
jsonString = sr.ReadToEnd
Dim jsonThing As New jsonStuff(jsonString)
For Each returnedBusiness As yelpResponse.business In jsonThing.myYelpResponse.businesses
Dim myNewBusiness As New yelpBusiness
myNewBusiness.lblBusinessName.Text = returnedBusiness.name
myNewBusiness.lblAddress1.Text = returnedBusiness.address1
myNewBusiness.lblAddress2.Text = returnedBusiness.city & ", " & returnedBusiness.state_code & " " & returnedBusiness.zip
myNewBusiness.lblReviewCount.Text = returnedBusiness.review_count & " Reviews"
myNewBusiness.imgRatingStars.Source = New BitmapImage(New Uri(returnedBusiness.rating_img_url))
myNewBusiness.imgPlacePhoto.Source = New BitmapImage(New Uri(returnedBusiness.photo_url))
myNewBusiness.lblReadReviews.NavigateUri = New Uri(returnedBusiness.url, UriKind.Absolute)
myNewBusiness.lblReadReviews.TargetName = "_blank"
myNewBusiness.btnLeaveReview.NavigateUri = New Uri("http://www.yelp.com/writeareview/biz/" & returnedBusiness.id)
myNewBusiness.btnLeaveReview.TargetName = "_blank"
placesMainPanel.Children.Add(myNewBusiness)
Next

myThrobber.Visibility = Visibility.Collapsed
End Sub




Imports System.Runtime.Serialization.Json
Imports System.Runtime.Serialization

<DataContract()> _
Partial Public Class yelpResponse

<DataMember()> _
Public Property message As yelpMessage

<DataMember()> _
Public Property businesses As List(Of business)

Public Class yelpMessage

Public Property text As String
Public Property code As Integer
Public Property version As String
End Class

Public Class business
Public Property rating_img_url As String
Public Property country_code As String
Public Property id As String
Public Property is_closed As Boolean
Public Property city As String
Public Property mobile_url As String
Public Property review_count As Integer
Public Property zip As String
Public Property state As String
Public Property latitude As Double
Public Property rating_img_url_small As String
Public Property address1 As String
Public Property address2 As String
Public Property address3 As String
Public Property phone As String
Public Property state_code As String
Public Property categories As List(Of category)
Public Property photo_url As String
Public Property distance As Double
Public Property name As String
Public Property neighborhoods As List(Of neighborhood)
Public Property url As String
Public Property country As String
Public Property avg_rating As Double
Public Property longitude As Double
Public Property nearby_url As String
Public Property reviews As List(Of review)
Public Property photo_url_small As String

End Class

Public Class category
Public Property category_filter As String
Public Property search_url As String
Public Property name As String

End Class

Public Class neighborhood
Public Property url As String
Public Property name As String


End Class

Public Class review
Public Property rating_img_url_small As String
Public Property user_photo_url_small As String
Public Property rating_img_url As String
Public Property rating As Integer
Public Property mobile_uri As String
Public Property url As String
Public Property user_url As String
Public Property text_excerpt As String
Public Property user_photo_url As String
Public Property date1 As String
Public Property user_name As String
Public Property id As String

End Class
End Class




26 comments:

  1. Confused about 'jsonStuff' object?

    ReplyDelete
  2. Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work. Buy Yelp Reviews

    ReplyDelete
  3. Doors open very often for persons who buy Twitter followers and use the additional boost correctly. The startup of followers is not essentially the end of your promotion plan, it must be merely the start.Buy Twitter Followers

    ReplyDelete
  4. The sponsored posts are linked to the user’s profile, where another user can decide to be a follower.Buy Twitter Followers

    ReplyDelete
  5. Are you seeing to Buy Full Email Verified SC Accounts as foremost profile otherwise additional? If yes, you could get the prepared Email Verified Sound Cloud Accounts. Everybody knows around Sound cloud Social Media Auditory site. Really it is the Audio Melody site in USA. There are lots of Music Group in this website like HipHop, Traditional, Deep-House, Substitute Rock etc. Buy Full Email Verified Soundcloude Account

    ReplyDelete
  6. When you own a business, you know very well that customer reviews are extremely influential. From Google To FACEBOOK people are sharing their experiences on all, and what they say has a huge impact. Over 90% of contributors claimed that online positive reviews influenced their purchasing decision, and 85% said their decision was influenced by minus reviews.Buy Google 5 star Reviews

    ReplyDelete
  7. Business can power up their relationship with customers by straightly linking with reviewers on Google. Buy Google Reviews

    ReplyDelete
  8. Investigation displays that online reviews drive additional sales than customary marketing means for example social media, advertising, as well as organic search results. Buy Google 5 Star Reviews

    ReplyDelete
  9. Google reviews can either be positive or negative for your business, stores, office, restaurant, service or requirements. Google is the largest search engine, as well as the most efficient advertisement website.Buy Google 5 star Reviews

    ReplyDelete
  10. Many business persons out there are worried about whether buying negative reviews is a good idea or not due to its safety. You can contact us at MangoCityIT and let us take you through a process that will make you understand the importance of these reviews and how we make them appear more realistic and safe for your business. Buy Negative Reviews

    ReplyDelete
  11. we perform operate work owing to you. As you Product mainly founded web page /apps desire continue rated, thou accomplish get a lot above clients through online.Buy Google Negative Reviews

    ReplyDelete
  12. Clients are more prone to write about negative experiences online. It’s the simplest means to get back at terrible client service. If you are neglecting or ignoring the power of negative customers’ reviews, you are making a huge mistake.Buy 1 star Google Reviews

    ReplyDelete
  13. Buy Google Reviews is a new era of advertising and service in which your business/brand is defined by those who experience it. Buy Negative Google Reviews

    ReplyDelete
  14. We provides the most genuine Google Reviews, and it is exactly what your business firm needs to achieve success in the world of business.Buy Google reviews Cheap

    ReplyDelete
  15. The key features of this service are that all page reposts are permanent). Second, you’ll get 100% satisfaction assurances. The service delivery time is 10 hours. No programs, bots, or software are used in this service. When you buy this service, it’s a 100 %stable and safe account, with real high-class campaigns as well as 100 % safety and security, as well as customer satisfaction. With this service, you’ll save time and effort. You’ll experience improvements within 24 hours.
    Buy SoundCloud Play

    ReplyDelete
  16. These are not new to the business. we’ve been dealing in business since we had a business.Buy Google Reviews

    ReplyDelete
  17. These are not new to the business. we’ve been dealing in business since we had a business.Buy Google Reviews

    ReplyDelete
  18. We would like to present you to SoundCloud Viral wherever we do as the name suggests – make you viral on Sound Cloud.Buy SoundCloud Plays Promotion

    ReplyDelete
  19. Thinking before buying Google reviews is not a bad idea. This write up will help you in the making the decision to purchase Google Reviews for your business! Buying Google reviews applies to both those who are in business for the first time as well as those who already have an account. Buy Google Negative Reviews

    ReplyDelete
  20. Mangocity IT Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work. Buy Yelp Reviews

    ReplyDelete
  21. Top Promoter This is really a nice and informative, containing all information and also has a great impact on the new technology. Check it out here: Facebook Promotion

    ReplyDelete
  22. Top SEO Work Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists. Old Gmail Accounts

    ReplyDelete
  23. read that Post and got it fine and enlightening. If you don't mind share more like that... Buy Press Releases

    ReplyDelete


  24. Buy Soundcloud Service

    This is my first time i visit here. I discovered such a large number of fascinating stuff in your online journal particularly its dialog. From the huge amounts of remarks on your articles, I figure I am by all account not the only one having all the satisfaction here! keep doing awesome BUY POSITIVE GOOGLE REVIEWS

    ReplyDelete
  25. I love reading through this article because it is full of excellent information and interesting facts. The Data Contract Serializer sounds like a really cool program. Browse around this website to get breaking news on google reviews.

    ReplyDelete