|
Yahoo SiteExplorer API With C#
By Manoj Jasra
Expert Author
Article Date: 2007-08-14
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;
}
Comments
About the Author:
Manoj Jasra is an online marketing veteran of almost 10 years who specializes in analytics, social/search strategy and mobile marketing. Manoj is currently a Sr. Strategist at one of Canada’s largest Telecommunications Companies, Shaw Communications Inc., where he leads Social Media, SEO, PPC and Web Analytics strategies. Manoj first started in the search marketing industry with Enquiro Search Solutions, where he spearheaded web analytics, SEO Training and the development of cutting edge search marketing solutions for clients.
Manoj is a Professional Speaker having participated at events such as Emetrics, Web Analytics Xchange, WebTrends’ Engage, Internet Marketing Conference, Social Media Innovation Summit and Search Engine Strategies. He authors Web Analytics World (a top 100 Online Marketing Blog) and consults through his firm Jasra Inc.
|