Quantcast

Yahoo SiteExplorer API using C#


If you are interested in using Yahoo’s SiteExplorer API and are coding in the ASP.NET environment using C# (web pages) then the following method might be of use to you. This method is used for returning the number of pages indexed or incoming links for a given domain. It basically takes in the parameters of your Yahoo API key, the URL, the number of results you want returned, operation (used for link command vs. site command) and a final parameter which removes internal links for the output.

The output of this method will be XML which you will have to parse through looking for items such as ResultSet and totalResultsAvailable.


public static String returnYahooXML(String APPID, String domain, Int32 results, Int32 operation, Boolean omitnInlinks)
{
StringBuilder urlBuffer = null;

if (operation == 0)
urlBuffer = new StringBuilder(” http://api.search.yahoo.com/SiteExplorerService/V1/inlinkData”);
else
{
urlBuffer = new StringBuilder(“http://api.search.yahoo.com/SiteExplorerService/V1/pageData”);
}

urlBuffer.Append(“?appid=”);
urlBuffer.Append(APPID);
urlBuffer.Append(“&query=”);
urlBuffer.Append(domain);
urlBuffer.Append(“&results=”);
urlBuffer.Append(results);
if (operation == 0)
{
if(omitnInlinks)
{
urlBuffer.Append(“&omit_inlinks=”);
urlBuffer.Append(domain);
}
}

try
{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(urlBuffer.ToString());

req.ContentType = “text/xml;charset=\”utf-8\”";
req.Accept = “text/xml”;
req.Method = “POST”;
Stream stm = req.GetRequestStream();

stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);


return r.ReadToEnd();
}
catch (Exception ex)
{
//error code here
}
return String.Empty;

}

Subscribe by Email

Speak Your Mind

*