Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
Like it? Share:

Warning: Missing argument 1 for BaseDD::BaseDD(), called in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-manual.php on line 123 and defined in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-class.php on line 97

Warning: Missing argument 2 for BaseDD::BaseDD(), called in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-manual.php on line 123 and defined in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-class.php on line 97

Warning: Missing argument 3 for BaseDD::BaseDD(), called in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-manual.php on line 123 and defined in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-class.php on line 97

Warning: Missing argument 4 for BaseDD::BaseDD(), called in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-manual.php on line 123 and defined in /home/agicheco/public_html/wp-content/plugins/digg-digg/include/dd-class.php on line 97
 

MOZ or formerly SEOmoz is the best search engine optimization suite that provides lot of SEO tools that help you in research on global most important SEO aspects.

What I like the most from this service is the ease and full reporting on information that you can’t find anywhere else. Using Moz API we can extract lot of important data by accessing some of the endpoints that MOZ offers.

An endpoint is a resource available in Mozscape and current available are:

  • URL metrics
  • Link metrics
  • Anchor text metrics
  • Top pages
  • Metadata

In this post I’m going to write about accessing URL metrics and getting data regarding some URL like MOZRank, Domain Authority, MOZ External Links, MOZ Total Links and other info that these days is very valuated by SEO industry.

We are going to use the MOZ Free API Access without paying. In Free API Access there are 2 types of limitations:

  • First, is the parameters that you can get – Check this link for more info and see what data is availabe with Free Access http://apiwiki.moz.com/url-metrics
  • Second, there is rate limit of one request every 10 seconds – but this is not always true because I got results within 2,3 seconds in 50% of the requests

Create MOZ Free Account

To be able to use Free MOZ API first thing that you must do is create free account.

To do so visit this link: https://moz.com/community/join

Fill the form there and make sure you use real email because you will need to validate your account and that’s it.

Generate your Access ID and API key

Second step is to generate Access ID and API key that we are going to use in our example to get data.

So after signup login to MOZ and visit: http://moz.com/products/api/keys

Click “Generate Secret Key” in the box below and your data will be generated. After completion of the process you should see screen like this:

Getting MOZ Data

After getting your Access ID and API Secret key you can now code the PHP script for getting MOZ Data.

In below example I show you how you make a call to MOZ API and get MOZRank, Domain Authority, External and Total Links for specific domain.

<?php

//Your Access ID and Secret Key
$accessID = "member-xxxxxxxxx";
$secretKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

//Set domain that you need data for
$domain = 'example-domain.com';

//Expires parameter must be set in near future because MOZ API does not allow parameters set far long in future and will return error
$expire_in = time() + 500;

$SignIn = $accessID."n".$expire_in;

$binarySignature = hash_hmac('sha1', $SignIn, $secretKey, true);
$urlSafeSignature = urlencode(base64_encode($binarySignature));

//What data we want to get, we calculate all numbers together
$data = "68719495200";

$curlURL = "http://lsapi.seomoz.com/linkscape/url-metrics/?Cols=".$data."&AccessID=".$accessID."&Expires=".$expire_in."&Signature=".$urlSafeSignature;

$Domains = array($domain);
$Domains = json_encode($Domains);

//User CURL for sending request
$options = array(
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_POSTFIELDS     => $Domains
	);

$ch = curl_init($curlURL);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close( $ch );

$response = json_decode($response);
print_r($response);

Replace Your Access ID, Secret Key, add the Domain in the script and you will get array of results for:

  • Moz Rank – 16384 (umrp, umrr), The MozRank of the URL, in both the normalized 10-point score (umrp) and the raw score (umrr)
  • Domain Authority – 68719476736 (pda), A normalized 100-point score representing the likelihood of a domain to rank well in search engine results
  • External Links – 32 (ueid), The number of external equity links to the URL
  • Links – 2048 (uid), The number of links (equity or nonequity or not, internal or external) to the URL

The response that you will get should look like this:


Array
(
    [0] => stdClass Object
        (
            [pda] => 19.8114141723
            [ueid] => 1
            [uid] => 1
            [umrp] => 2.69267070574
            [umrr] => 5.93757244179E-13
        )

)

From the numbers I wrote above you probably see how the $data parameter is created.. We just calculate all numbers 16384 + 68719476736 + 32 + 2048 = 68719495200

Using this script you can get all data that are allowed in Free MOZ API, while if you want some other data that is not Free then you must choose one of the MOZ Pro API packages.




Other Posts You Might Like


12 responses to “Get Moz API data using PHP”

  1. ad says:

    There is a limit of the API?

    if we do a bulk, it’s not working ?

    • agiche says:

      There is limit, 1 request per 10 seconds… but as I wrote in post in most of cases result is returned less than 10 seconds..

      For bulk check it should work if you follow the rules regarding limit that is set from MOZ.

  2. Jon Hogg says:

    Is there a way to fetch data using JSONP?

  3. Ellys says:

    i dont understand how to use it…any more tutorial for it.

    • agiche says:

      Hi Ellys, MOZ has changed their process of activation recently.. I will update this post today with new information.

    • agiche says:

      I have reviewed MOZ process and the script all is fine and still working. Just follow the steps above should be a straightforward process to implement the code where you need it.

      If you still can’t figure out, let me know and I will create short video how to go over the steps.

  4. Bary says:

    Hi,

    How to manage url with accents (for example http://fr.wikipedia.org/wiki/Géant_(film)). If I let the url as is I have got {“pda”:1,”ueid”:0,”uid”:0,”upa”:1,”ut”:””,”uu”:””} but if I urlencoded I have always got {“pda”:100,”ueid”:0,”uid”:0,”upa”:1,”ut”:””,”uu”:””}. Thanks

    • agiche says:

      MOZ only accepts exact match on the url.. so if you do urlencode MOZ at the end won’t decode it but take it as it is and get back to u information about that encoded url.

      If u go here: http://www.opensiteexplorer.org/ and enter the url that u pointed as example it will throw an error, so it means at the moment MOZ does not parse the urls with accents..

      If they would then only that you should send it urlencode(htmlentities(URL)) to convert it to the right format.

  5. Kevin Steger says:

    Is this method still valid?

    Here is my output:

    { “status” : “401”, “error_message” : “Your authentication failed. Check your authentication details and try again. For more information on signed authentication, see: http://apiwiki.moz.com/signed-authentication” }1

    • agiche says:

      Hi Kevin, yes it is still valid and working. As the error says, check your MOZ Account login details. Maybe the account is not activated, or maybe is old and suspended, etc.

  6. kushal says:

    hi , thanks for the code , can you please provide me code for accessing Link metrics ? any help would be appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.

Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014
JVZoo IPN API in PHP

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook

Archive

X

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.