GithubHelp home page GithubHelp logo

seomoz / seomozapisamples Goto Github PK

View Code? Open in Web Editor NEW
161.0 132.0 140.0 1.9 MB

Mozscape API sample code

Home Page: https://moz.com/products/api

License: MIT License

Java 91.57% PHP 4.49% Python 2.35% Ruby 0.41% Perl 0.86% JavaScript 0.32%

seomozapisamples's Introduction

Mozscape API Sample Code

Welcome to the Mozscape API sample code. Please let us know if you have any questions and send along any examples you'd like to contribute.

seomozapisamples's People

Contributors

alecdeason avatar aur1mas avatar b4hand avatar brianzhou13 avatar fayland avatar flyingmana avatar kennethlmartin avatar macklevine avatar nstielau avatar phs avatar prabeesh avatar shawjb avatar whatisdot avatar yhorian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

seomozapisamples's Issues

python issue

After getting urls from beautifulscoup unable to pass it to the mozapi to get page autority

anchorTermResults = client.anchorText('www.moz.com/blog')

gives me the error

HTTP Error 403: Permission denied: fnajgiabgpaohkbjgnaieochegddeddafi.

Sometimes Data is not Showing

Hi, Sometimes the data are not showing. for (page authority,dmoz rank) i need to re do the test/ then it will come up:

Here is my code:

	/* Get SEOmoz Data
	-------------------------------------------------- */
		public function getSeoMoz($domain, $accessid = "", $secret = "")
		{
			try
			{
				$access_id = (empty($accessid) ? $_SESSION['SEOMOZ_API_ACCESSID'] : $accessid);
				$secret_key = (empty($secret) ? $_SESSION['SEOMOZ_API_SECRETKEY'] : $secret);
                                $expires = time() + 5000;
				$stringToSign = $access_id."\n".$expires;
				$binarySignature = hash_hmac('sha1', $stringToSign, $secret_key, true);
				$urlSafeSignature = base64_encode($binarySignature);

			$callback_url = "http://lsapi.seomoz.com/linkscape/url-metrics/www." . $domain . "?";
				$data = array(
					'Cols'		=> '68719493120',
					'AccessID'	=> $access_id,
					'Expires'	       => $expires,
					'Signature'	=> $urlSafeSignature
				);

				$curl_response = $this->curl->get($callback_url . http_build_query($data, '', '&'));

				if ($curl_response->headers['Status-Code'] == "200") {
					$parse_response = json_decode($curl_response, true);
					$domain_authority = $parse_response['pda'];
                                        $mozrank = $parse_response['umrp'];

                    $response = array(
						'status' => 'success',
						'data' => array(
						'domain_authority' => (int)round($domain_authority),
                                                'mozrank' => (int)round($mozrank)
						)
					);
                                        } else {
                                                   $response = array(
						        'status' => 'error',
						           'msg' => 'SEOMoZ Response Error.'
					);
                                      }
			            }
			  catch (Exception $e)
			                              {
				                       $response = array(
					                     'status' => 'error',
					                        'msg' => $e->getMessage()
				                        );
			         }
			return $response;		
		}

Getting uncompleted $contents.

Has anyone encounter same situation as we do?
Sending a $batchedDomains containing 50 domains, however I receive only 49 responses of $contents.

Constant not defined

In the PHP examples, the constant LINKS_COL_URL is not defined.

Line 25: 'link_cols' => LINKS_COL_URL,

This constant should be defined in links_constants.php

PHP Library mistakingly converts to POST

Line 35 of ConnectionUtil.php should read:
if (is_array($postParams) && count($postParams) > 0) {

instead of just:
if (count($postParams) > 0) {

latest versions of php 5.3 made a change where an empty string passed to count returns 1, so this code will think $postParams = "" should be a post, which it typically is for the metrics calls.

I recently upgraded my php version to find this error. Everything was working fine prior.
Here is someone's php comment suggesting change:

http://php.net/manual/en/function.count.php#98291

Different Result Between API & Moz Result

Hi there
I just tried the example PHP Code to get the DA & PA data and the result is different compared to result from Moz website.

Sample code result:
{"uu":"www.seomoz.org/","upa":64,"pda":77}

Moz result:
DA: 81
PA: 84

Python sample broken

The code example is not functional:

    class MozscapeError(StandardError):
E   NameError: name 'StandardError' is not defined

PHP API change the values of the url metrics constants to ints

Just a thought, but you may want to consider changing the constants defined in php/complete/constants/url_metrics_constants.php to integers instead of strings. Should make something like the following easier to use:

$cols = URLMETRICS_COL_EXTERNAL_LINKS + URLMETRICS_COL_LINKS + URLMETRICS_COL_MOZRANK;

External Equity Links should be added in the Free Columns

I'm using the Python library and when I look at the lsapi.py file I see that the externalLinks column (with the BitFlag of 32) says it's not available to users with a free account. However, when I reference your API documentation it shows that it is available with a free account. See here

Can we add this to the lsapi.UMCols.freeCols attribute?

Python - "links" function missing capability

In the "mozscape.py" file, the links function does not include all possible parameters. Notably, the Limit and Offset parameters do not exist. Could these features be added, so use of the API for python developers does not require building another module from a third-party library like requests?

def links(
            self, url, scope='page_to_page', sort='page_authority',
            filters=['internal'],
            targetCols=(UMCols.url | UMCols.pageAuthority),
            sourceCols=(UMCols.url | UMCols.pageAuthority),
            linkCols=0):
        """This is currently broken. Have not figured it out"""
        return self.query(
            'links/%s' % quote(url),
            Scope=scope,
            Sort=sort,
            Filter='+'.join(filters),
            TargetCols=targetCols,
            SourceCols=sourceCols,
            LinkCols=linkCols)

Thank you for considering this request.

PHP Examples not working

I've set the values for the API Keys.

The files contained within the examples folder hangs and does not receive a response when run:

/php/complete/examples/

However, I am getting a successful response from these PHP files when run:

/php/signed_authentication_sample.php
/php/batching_urls_sample.php

Is there anything I'm missing?

Thanks!
Mark

print_r

I have notices that in all PHP services "print_r($urlToFetch);" is left. Is this necessary?

Permission denied (python)

Running the example in python with newly generated credentials gives me this :/ Not sure what to understand from that.

I see "Permission denied" — but I'm not sure what more to do

 laurentfite@cest-pas-moi  ~/workspace/moz-domainauthority/SEOmozAPISamples/python   master ● ?  python3 example.py                                   1 ↵  5880  16:09:42
Traceback (most recent call last):
  File "/Users/laurentfite/workspace/moz-domainauthority/SEOmozAPISamples/python/mozscape.py", line 338, in query
    return json.load(reader(urlopen(request, data)))
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Permission denied: pcklmkkmopjgphjdpcigohkbmmkfmkljniklmd

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "example.py", line 16, in <module>
    metrics = client.urlMetrics(['www.moz.com', 'www.moz.com/blog'])
  File "/Users/laurentfite/workspace/moz-domainauthority/SEOmozAPISamples/python/mozscape.py", line 360, in urlMetrics
    Cols=cols)
  File "/Users/laurentfite/workspace/moz-domainauthority/SEOmozAPISamples/python/mozscape.py", line 342, in query
    raise MozscapeError(e.read())
mozscape.MozscapeError: b'{\n        "status" : "401",\n        "error_message" : "Permission denied: pcklmkkmopjgphjdpcigohkbmmkfmkljniklmd"\n      }'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.