aseo/api

Analytics SEO Api 客户端

0.0.8 2016-10-31 10:01 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:39:51 UTC


README

安装

通过 Composer

  1. 运行命令: composer require "aseo/api:*"

手动安装

  1. 克隆此仓库: git clone git@github.com:analyticsseo/php-api-client.git
  2. 切换到克隆的文件夹,例如: cd php-api-client
  3. 运行命令 composer install

测试您的安装

  1. 浏览到文件夹 tests\functional
  2. 编辑文件 serps.php,添加您的凭据,并保存。
  3. 运行 php serps.php

不要忘记编辑 serps.php 文件并添加您的凭据,否则所有测试都将失败

示例用法

<?php
// Uncomment the following if you run this file directly, any modern framework
// deals with autoloading out of the box.
// include  '<PATH TO COMPOSER AUTOLOAD FILE'; 

// Initialize the HTTP Transport Layer.
$guzzle = new Guzzle\Http\Client('http://v3.api.analyticsseo.com');

// Setup Request Authentication.
$auth = new Aseo\Api\Auth\KeyAuth;

// Do not forget to change API_KEY, API_SECRET, and SALT with
// the values provided by Analytics SEO.
$auth->setApiKey(API_KEY);
$auth->setApiSecret(API_SECRET);
$auth->setSalt(SALT);


// The V3 SERPs Client.
$serps = new Aseo\Api\V3\Serps\SerpsApiClient($guzzle, $auth);

// Set to true to output raw http requests.
$serps->debug = false;

// Define query paramaters, as per documentation.
$query = array(
  'region'=>'global',
  'search_engine' => 'google',
  'phrase' => 'abc',
  'language' => 'en',
);

// Create a SERPs request object.
$data = new Aseo\Api\V3\Serps\SerpsRequest($query);

// Make the call.
$searchResultsResponse = $serps->searchResults($data);

// Store the job id, this will be used to fetch the data as soon as the job is
// done.
$jobId = $searchResultsResponse['jid'];

// Check to see if job is ready. If not, try again later. You can also execute
// all queries, store the job ids, and later query to see each job id is ready.
while (true) {
  $fetchJobResponse = $serps->fetchJobData($jobId);
  if (false == $fetchJobResponse['ready']) {
    sleep(60);
    continue;
  }
  var_export($fetchJobResponse);
  break;
}