Forum Moderators: coopster

Message Too Old, No Replies

Accessing Overture via PHP - API?

Is an Overture API available?

         

erikcw

12:48 am on Jun 21, 2004 (gmt 0)

10+ Year Member



Hello,

I am trying to write a script in php that will allow me to access the overture keyword "inventory". (http://inventory.overture.com/d/searchinventory/suggestion/) Can anyone tell me how to access the overture system in a way similar to the desktop app "Good Keywords"?

Thanks!

jatar_k

5:19 pm on Jun 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at curl [ca.php.net]

erikcw

10:40 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



So this is what I have so far:

This script seems to pull the entire page at $url.


$url = "http://inventory.overture.com/d/searchinventory/suggestion/";
$curl = curl_init ();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_HEADER, 0);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close($curl);
print $result;

How do I POST data to this URL and then extract just the keywords and keyword counts from the overture tool? I'd like to take just that data and store it in a variable...

Thanks!

jatar_k

11:01 pm on Jun 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



here's a curl function we use, the comments are pretty good

$url = "https://www.example.com/somescript.php";
$postfields = "function=$func&var2=$mid&var3=$value3&var4=$value4&var5=value5&";
// Creating an array of email addresses and their amounts.
$postfields .= "payment[]=someone@example.com$4.30&";
$postfields .= "payment[]=someone@example.c$3.54&";
$postfields .= "payment[]=someone@example.com$4.54&";
$postfields .= "payment[]=someone@example.com$5.54&";

// Initialising a new session and returns a CURL handle for use.
$ch = curl_init();

// Processing
$reply = api_process($ch, $url, $postfields, $error);
echo "<PRE> Access Reply:";
if (empty($error)) {
print_r($reply);
echo "</PRE>";
} else {
print_r($error);
echo "</PRE>";
exit();
}

function api_process($curl_handle, $url, $postfields, &$error)
{
curl_setopt($curl_handle, CURLOPT_URL, $url);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, 1);

// Do not want the HEADER to be displayed in the output of this code.
curl_setopt($curl_handle, CURLOPT_HEADER, 0);

// Want CURL to actuall POST the information just as if you were posting it
// from a form instead of using GET or REQUEST methods.
curl_setopt($curl_handle, CURLOPT_POST, 1);

// Defined which data to actually post
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $postfields);

// Prevents CURL from following any header("Location: url") responses from
// the server that it has connected to. Since we want to process this transaction
// results ourself, we want to avoid this, so set this value to 0.
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 0);

// Allows CURL to directly return the transfer instead of printing it out directly.
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

// Prevents SSL verification.<-- Remove if verification required.
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 0);

// Executes the predefined CURL session
$result = curl_exec ($curl_handle);
//$result = curl_multi_exec ($curl_handle);

// Capturing an error, if any.
$error = curl_error ($curl_handle);

return $result;
}

once you get result you would have to parse that information to extract the data that you need. Possibly using some of the Regular Expression Functions (Perl-Compatible) [ca.php.net]

erikcw

1:33 am on Jun 22, 2004 (gmt 0)

10+ Year Member



Thanks! That script worked like a charm! Any suggestions on how to start with the REGEX? I've used regex on anything that "large" before. Basically I want to strip everything but the keywords from the overture inventory.

erikcw

5:38 am on Jun 22, 2004 (gmt 0)

10+ Year Member



Also, what is the difference between using cURL and fsockopen()? What are the pro/cons of each method?

AcornDomains

11:06 pm on Jul 20, 2004 (gmt 0)

10+ Year Member



Hi,

I am trying to do the same thing with Overture as you, did you get it to work?

Are you able to share the code? I have done it in a Delphi application but now want a PHP version for my web site.

Many thanks