PHP code example of raysolomon / php-oauth-client
1. Go to this page and download the library: Download raysolomon/php-oauth-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
raysolomon / php-oauth-client example snippets
$clientId = ''; // fill in this
$clientSecret = ''; // fill in this
$consumer = new \RaySolomon\OAuthClient\OAuthConsumer($clientId, $clientSecret);
$url = "https://yboss.yahooapis.com/ysearch/web";
$query = 'Automotive Tune Up Service Mesa, AZ';
$args = [];
$args["q"] = $query;
$args["format"] = "json";
$args["count"] = 10;
$args["start"] = 0;
$request = \RaySolomon\OAuthClient\OAuthRequest::from_consumer_and_token($consumer, null, "GET", $url, $args);
$request->sign_request(new \RaySolomon\OAuthClient\OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
$url = sprintf("%s?%s", $url, \RaySolomon\OAuthClient\OAuthUtil::build_http_query($args));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'MyUserAgent/1.2.1 (+https://www.example.com/bot.html)');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 600);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array(
$request->to_header()
)
);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new \Exception('YahooBoss: ' .
sprintf('Request failed: (%d) %s.', curl_errno($ch), curl_error($ch)));
}
curl_close($ch);
var_dump($response);
bash
composer