Search Engine Rank Tracker - RankTrackr Access Snippet


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. CURLOPT_URL => $query,
  33. CURLOPT_POST => true,
  34. CURLOPT_RETURNTRANSFER => true,
  35. CURLOPT_POSTFIELDS => "email=$this->username&password=$this->password"
  36. ));
  37.  
  38. $data = curl_exec($this->ch);
  39.  
  40. if (!$data) {
  41. return false;
  42. }
  43.  
  44. $object = json_decode($data);
  45. //var_dump( $object );
  46.  
  47. if ($object && $object->access_token) {
  48. $this->token = $object->access_token;
  49. }
  50.  
  51. return true;
  52. }
  53.  
  54.  
  55. function get_all_urls() {
  56. $params = array(
  57. 'access_token' => $this->token
  58. );
  59.  
  60. $query = $this->host . 'urls?' . http_build_query($params);
  61.  
  62. $this->ch = curl_init();
  63. CURLOPT_URL => $query,
  64. CURLOPT_RETURNTRANSFER => true,
  65. CURLOPT_HEADER => true,
  66. CURLOPT_HTTPHEADER => array('Content-Type: application/json')
  67. ));
  68.  
  69.  
  70. $data = curl_exec($this->ch);
  71.  
  72. //$info = curl_getinfo($this->ch);
  73.  
  74. if (!$data) {
  75. return false;
  76. }
  77.  
  78. var_dump ( $data );
  79.  
  80. $object = json_decode($data);
  81.  
  82. var_dump ( $object );
  83.  
  84. return $object;
  85. }
  86.  
  87. }
  88.  
  89.  
  90. // Example usage:
  91. $ranks = new RankTrackr();
  92. $ranks->get_auth_token();
  93. $ranks->get_all_urls();

URL: http://ranktrackr.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.