HomePHP 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.
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:
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.
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: