#Yelp API implemented in C# @yelpdev
Yelp offer an API that allows you extract their data in JSON format; really cool, and a very useful resource. If you’re using C#, then you can use this code to access it (I’ve removed the access key and client id)
static void Main(string[] args)
{
var strUrl = “https://api.yelp.com/oauth2/token”;var strPostData = “grant_type=client_credentials”;
strPostData += “&client_id=A-xxxxx”;
strPostData += “&client_secret=xxxxx”;
WebClient wc = new WebClient();
var strResponse = wc.UploadString(strUrl, strPostData);
var login = JavascriptDeserialize<OAuthLogin>(strResponse);//var strSearch =
// “https://api.yelp.com/v3/businesses/search?term=bar&latitude=51&longitude=0.1”;var strSearch = “https://api.yelp.com/v3/businesses/the-crow-and-gate-crowborough”;
wc.Headers.Add(“Authorization”, “Bearer ” + login.access_token);
var strSearchResponse = wc.DownloadString(strSearch);
}public static T JavascriptDeserialize<T>(string json)
{
var jsSerializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
return jsSerializer.Deserialize<T>(json);
}public class OAuthLogin
{
public string token_type { get; set; }
public int expires_in { get; set; }
public string access_token { get; set; }
}