I am having problem with the yahoo search API,sometimes it works and sometimes don't why I am getting problem with that

I am using this URL

http://api.search.yahoo.com/WebSearchService/rss/webSearch.xml?appid=yahoosearchwebrss&query=originurlextension%3Apdf+$search&adult_ok=1&start=$start

The code is given below:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">          
 
<?
$search = $_GET["search"];
$replace = " "; $with = "+";
$search = str_replace($replace, $with, $search);
 
if ($rs = $rss->get("http://api.search.yahoo.com/WebSearchService/rss/webSearch.xml?appid=yahoosearchwebrss&query=originurlextension%3Apdf+$search&adult_ok=1&start=$start")) 
{
 
}
 
// Go through the list powered by the search engine listed and get the data from each <item>
$colorCount="0";
 
   foreach($rs['items'] as $item) 
	{ 
 
	// Get the title of result
 
	   $title = $item['title'];
 
	// Get the description of the result
 
	   $description = $item['description'];
 
	// Get the link eg amazon.com
 
	   $urllink = $item['guid'];
 
if($colorCount%2==0)
{
$color = ROW1_COLOR;
}
else
{
$color = ROW2_COLOR;
}
 
include "resulttemplate.php";
$colorCount++;
 echo "\n"; 
 
}  
?>

Sometimes it gives results and sometimes don't...I get this error usually

Warning: Invalid argument supplied for foreach() in /home4/thesisth/public_html/pdfsearchmachine/classes/rss.php on line 14

Can anyone help..

Recommended Answers

All 19 Replies

Previously i have explained you reason for foreach error.
Also as i said your given API string is not working for me.

Here is API link i found for yahoo.
http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=yahoo

You can find more parameter options here.
http://developer.yahoo.com/search/web/V1/webSearch.html

Thanks a lot for your reply

So which String I need to use instead of http://api.search.yahoo.com/WebSearchService/rss/webSearch.xml?appid=yahoosearchwebrss&query=originurlextension%3Apdf+$search&adult_ok=1&start=$start

can you please tell ..I am confused ,It makes my application hell

Try this

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">    
<?

$search = urlencode($_GET["search"]);
 
if ($rs = $rss->get("http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=$search")) 
{  
	// Go through the list powered by the search engine listed and get the data from each <item>
	$colorCount="0"; 
	if(count($rs['items']) >0)
	{
		foreach($rs['items'] as $item) 
		{  
			// Get the title of result 
			$title = $item['title']; 
			// Get the description of the result 
			$description = $item['description']; 
			// Get the link eg amazon.com 
			$urllink = $item['guid']; 
			if($colorCount%2==0)
			{
				$color = ROW1_COLOR;
			}
			else
			{
				$color = ROW2_COLOR;
			}		
			include "resulttemplate.php";
			$colorCount++;
			echo "\n"; 
	 
		}  
	}
	else
	{
		echo "No items in result";exit;
	}
}
else
{
	echo "No result in RSS parser";exit;
}
?>

M considering you have proper RSS reader class.

I wonder the other website http://pdf-download-engine.com uses same query and it works

You have to debug it and find the reason.
There is no rocket science.
So i told you to upload my last code on live so that i can debug.

ok,bro ,Thanks doing that

Hey.. m not bro.. m sis :)

ok,bro ,Thanks doing that

Oh ,Thanks sister,you really great ,Hoping to get the solution done

Nothing is printed ,I did ,It says some parse error :(

Actually these websites might have changed underlined architecture of the api and hence it is creating such problem....try to search correct and reliable source of api.....

Hey it is working on this link now.
What was issue?

I did not change anything ,I don't know wht was the issue,may be the API was down or yahoo limits the number of searches per IP like around 5000 ,i don't know ,same happened yesterday ,it was not working and than working than stops today and now again working ,I don't know what will be next ,I think i must move to bing API as it allows unlimited number of API calls ,yahoo charges if you exceed the number above 5000..do you suggest anything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.