Posted By

kundi on 09/05/13


Tagged

tracking seo rank checker tracker


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


Search Engine Rank Tracker - RankTrackr Access Snippet


 / Published in: PHP
 

URL: http://ranktrackr.com

RankTrackr PHP Snippet | SEO Rank Tracker This snippet will take search rankings (urls) from your RankTrackr account (http://ranktrackr.com) and allow you get data from your tracked urls / keywords.

  1. <?php
  2.  
  3. /*
  4. RankTrackr PHP Snippet | SEO Rank Tracker
  5. This snippet will take search rankings (urls) from your
  6. RankTrackr account (http://ranktrackr.com)
  7. */
  8.  
  9.  
  10. //enable error reporting
  11. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  12.  
  13.  
  14. class RankTrackr {
  15. public $token;
  16. public $username = '[email protected]';
  17. public $password = 'password';
  18.  
  19. public $host = 'http://users.ranktrackr.com/api/v1/';
  20.  
  21. public $ch;
  22.  
  23. public function __construct() {
  24. $this->ch = curl_init();
  25. }
  26.  
  27. function get_auth_token() {
  28. $query = $this->host . 'token';
  29.  
  30. $this->ch = curl_init();
  31.  
  32. curl_setopt_array($this->ch, array(
  33. CURLOPT_URL => $query,
  34. CURLOPT_POST => true,
  35. CURLOPT_RETURNTRANSFER => true,
  36. CURLOPT_POSTFIELDS => "email=$this->username&password=$this->password"
  37. ));
  38.  
  39. $data = curl_exec($this->ch);
  40.  
  41. if (!$data) {
  42. return false;
  43. }
  44.  
  45. $object = json_decode($data);
  46. //var_dump( $object );
  47.  
  48. if ($object && $object->access_token) {
  49. $this->token = $object->access_token;
  50. }
  51.  
  52. return true;
  53. }
  54.  
  55.  
  56. function get_all_urls() {
  57. $params = array(
  58. 'access_token' => $this->token
  59. );
  60.  
  61. $query = $this->host . 'urls?' . http_build_query($params);
  62.  
  63. $this->ch = curl_init();
  64. curl_setopt_array($this->ch, array(
  65. CURLOPT_URL => $query,
  66. CURLOPT_RETURNTRANSFER => true,
  67. CURLOPT_HEADER => true,
  68. CURLOPT_HTTPHEADER => array('Content-Type: application/json')
  69. ));
  70.  
  71.  
  72. $data = curl_exec($this->ch);
  73.  
  74. //$info = curl_getinfo($this->ch);
  75.  
  76. if (!$data) {
  77. return false;
  78. }
  79.  
  80. var_dump ( $data );
  81.  
  82. $object = json_decode($data);
  83.  
  84. var_dump ( $object );
  85.  
  86. return $object;
  87. }
  88.  
  89. }
  90.  
  91.  
  92. // Example usage:
  93. $ranks = new RankTrackr();
  94. $ranks->get_auth_token();
  95. $ranks->get_all_urls();

Report this snippet  

You need to login to post a comment.