Home arrow PHP arrow Getting Data from Yahoo Site Explorer Inbound Links API using PHP

Getting Data from Yahoo Site Explorer Inbound Links API using PHP

In the first part of this two-part series, you learned the importance and principles of Yahoo Site Explorer's inbound links API with respect to search engine optimization. If you read that part, you should already have your application ID, which will be used in your PHP script to make API calls. Also discussed in the first part is how to formulate the GET Request URL, and how to understand the responses from the inbound links API. In this part, you will start consolidating all of those inputs and implement what you've learned using a PHP server side scripting language.

TABLE OF CONTENTS:
  1. Getting Data from Yahoo Site Explorer Inbound Links API using PHP
  2. Unserializing the data
  3. Getting the data you need from the API raw response
  4. Getting the data
By: Codex-M
Rating: starstarstarstarstar / 2
November 19, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

The Basic Request and Response PHP Script

Yahoo Site Explorer's inbound links API provides sample PHP code to make requests and for receiving responses. The API documentation for using PHP in the application can be found in two places, here and here. The sample script at the second link is a very basic PHP code and does NOT include processing of data.

One of the first things you need to declare is to turn on reporting of all errors in PHP, which will be useful when debugging complicated and API applications:

error_reporting(E_ALL);

Next you need to declare your request variable. In the first part, you learned that this request URL will be used as a GET request to Yahoo.

$request = 'http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=TrnTAC3V34FlhDKeOScqpmw42Tu8B4BI8VUI7awsdcvfYIjJDwbtnb4rfNmmeQ--&query=http://www.php-developer.org&results=50&output=php';

The detailed discussion in how to formulate a GET request URL for Yahoo inbound links explorer API can be found in the part one of this tutorial.

Now that you have made a request, the vital third step is to receive the data from the Yahoo inbound links API and put into a string compatible for PHP processing. Using a PHP function called file_get_contents(), the entire response from Yahoo can be read into a string.

So it will be:

$response = file_get_contents($request);

IMPORTANT NOTE: Some web hosting companies, particularly those that offer free hosting plans, disable the file_get_contents PHP function. So it is highly recommended to check first with your hosting agency to make sure that the function has been enabled. If this is disabled, it appears to be impossible to develop useful PHP web applications with the API.

To detect problems with the response and receive process, you will need a conditional statement after the file_get_contents function:

//Step 4

if ($response === false) {

die('The request fails.');

}



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: