<?php
// Get your access id and secret key here: https://moz.com/products/api/keys
$accessID = "mozscape-02c27682b8";
$secretKey = "23d89133205a7b46f944ea6ddb2fead2";
// Set your expires times for several minutes into the future.
// An expires time excessively far in the future will not be honored by the Mozscape API.
$expires = time() + 300;
// Put each parameter on a new line.
$stringToSign = $accessID."\n".$expires;
// Get the "raw" or binary output of the hmac hash.
$binarySignature = hash_hmac('sha1', $stringToSign, $secretKey, true);
// Base64-encode it and then url-encode that.
$urlSafeSignature = urlencode(base64_encode($binarySignature));
// Add up all the bit flags you want returned.
// Learn more here: https://moz.com/help/guides/moz-api/mozscape/api-reference/url-metrics
$cols = "34359738368";
// Put it all together and you get your request URL.
$requestUrl = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$cols."&AccessID=".$accessID."&Expires=".$expires."&Signature=".$urlSafeSignature;
// Put your URLS into an array and json_encode them.
$batchedDomains = array('www.moz.com', 'www.apple.com', 'www.pizza.com');
$encodedDomains = json_encode($batchedDomains);
// Use Curl to send off your request.
// Send your encoded list of domains through Curl's POSTFIELDS.
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $encodedDomains
);
$ch = curl_init($requestUrl);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
curl_close( $ch );
$contents = json_decode($content);
print_r($contents);
?>
Warning: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' (this will throw an Error in a future version of PHP) in /in/r4dJZ on line 25
Warning: Use of undefined constant CURLOPT_POSTFIELDS - assumed 'CURLOPT_POSTFIELDS' (this will throw an Error in a future version of PHP) in /in/r4dJZ on line 26
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/r4dJZ:28
Stack trace:
#0 {main}
thrown in /in/r4dJZ on line 28
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/r4dJZ on line 25
Notice: Use of undefined constant CURLOPT_POSTFIELDS - assumed 'CURLOPT_POSTFIELDS' in /in/r4dJZ on line 26
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/r4dJZ:28
Stack trace:
#0 {main}
thrown in /in/r4dJZ on line 28
Process exited with code 255.
Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/r4dJZ on line 25
Notice: Use of undefined constant CURLOPT_POSTFIELDS - assumed 'CURLOPT_POSTFIELDS' in /in/r4dJZ on line 26
Fatal error: Call to undefined function curl_init() in /in/r4dJZ on line 28
Process exited with code 255.
Output for 5.1.2 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/r4dJZ on line 21
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.1
Fatal error: Call to undefined function hash_hmac() in /in/r4dJZ on line 11
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: hash_hmac() in /in/r4dJZ on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: hash_hmac() in /in/r4dJZ on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: hash_hmac() in /in/r4dJZ on line 11