Submit Your Site For Free!

Email Address:
* URL:
*
*Indicates Mandatory Field

Terms & Conditions

CProgramTrends
FlashNewz
DevWebPro








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 has been working in the search engine marketing industry since 2002. He started out as a software developer but now provides in-depth web site analysis using web analytics.

http://www.enquiro.com

Manoj is also the author of Web Analytics World. Web Analytics is an essential component in developing a successful online campaign. Help convert visitors into customers by understanding them.



Newsletter Archive | Article Archive | Submit Article | Advertising Information | About Us | Contact

C Programming Trends is an iEntry, Inc. ® publication - 1998-2008 All Rights Reserved Privacy Policy and Legal