Click here to Skip to main content
13,002,133 members (80,506 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 25 Feb 2013

Yahoo’s YQL API and C# Tutorial

, 25 Feb 2013
Rate this:
Please Sign up or sign in to vote.
A query language very similar to SQL that lets users query their multiple web services using a single unified language so that users wouldn’t have to learn multiple APIs.

Yahoo’s YQL

Yahoo’s YQL stand for Yahoo Query Language. It’s a query language very similar to SQL that lets users query their multiple web services using a single unified language so that users wouldn’t have to learn multiple APIs. The information about the service is here

The YQL Console

The YQL console gives you examples of the statements that are used to query Yahoo’s APIs. These queries are what we will use to send as a parameter to the YQL service. For instance,  in the screen shot below, we have a query making a request to Yahoo’s Local service and searching for fast food locations.

YQL Query

YQL Query searching Yahoo’s Local service for fast food locations.

Also note, there are other options that are included. We have the option of whether we want the information returned as XML or JSON. We can also choose if we want diagnostic and debug information returned in our result set. These options will function as the query-string parameters that we will send as part of our request to the YQL service.

  • q: The YQL query HTML encoded
  • format: This determines how we want our results (XML or JSON). The default is XML.
  • diagnostics: A true or false value that lets us select if we want our results to come back with diagnostic information from Yahoo

Take some time to play with the console and create the statements that you will like to send to the service.

This service is available to the public, so you don’t have to create an API key if you don’t want. Yet, there are some restrictions that may be applied to the times you can call it they may be affected if you are making an anonymous call.

Let’s Get Started

To get started, first we’ll open up Visual Studio and create a console project called YQLExample.


We need to add a few things to get this working. First, add a reference to the System.Web assembly. This will give us access to the HttpUtility class that will allow us to encode the query we will send.

Next, use the package console manager to get the Newtonsoft JSON serializer using this command:

PM> Install-Package Newtonsoft.Json

Now, add the following using statement to the file:

using System.Net;
using System.Web;
using Newtonsoft.Json.Linq;

The System.Net namespace will give us access to classes that will allow us to make the request to the web service and get results back. The Newtonsoft.Json.Linq namespace will give us access to classes that will help us to manipulate the returned JSON we will get back from the web service.

First, build the string which will be used as the URL to the web service.


Take note of the format parameter we are adding that will make the service give us our results as JSON and the diagnostics parameter that will keep the service from returning parameter information back to us.

Next, we will use the WebClient class to make a call to the service and to return our results back as a string.


Finally, we use the Newtonsoft JSON serializer that gives us access to powerful classes that let us manipulate our results from the web service call.


We turn the results from the web call to a JObject object using the Parse function from the JObject class. Then, we “travel” down the hierarchy of the JObject to cast our results as a JArray. This lets us have our results as an enumerable collection of JToken objects. We then loop through our collection and display the results to the console.


And that’s pretty much it. You can modify the YQL query that we send to the service as you like. I also advise playing with the console and checking out the YQL documentation. You will be amazed at the amount of information that is freely available.

Link to a “Gist” of the code in its entirety:

Related Links


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
Software developer in Nashville, TN(USA).

You may also be interested in...

Comments and Discussions

QuestionRemote server error Pin
Member 1002797630-Sep-13 23:59
memberMember 1002797630-Sep-13 23:59 
AnswerRe: Remote server error Pin
SleepyCrat8-Oct-13 5:41
memberSleepyCrat8-Oct-13 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 25 Feb 2013
Article Copyright 2013 by SleepyCrat
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid