Serpstat API v3 的 SDK

1.1.0 2018-07-26 12:17 UTC

This package is auto-updated.

Last update: 2024-09-29 03:26:01 UTC


README

Serpstat

这是 Serpstat API v3 的官方 SDK 库

入门指南

步骤 1: 创建认证令牌

SERPSTAT API 使用用户令牌进行请求认证。您可以在您的 个人资料页面 上创建令牌。

步骤 2: 安装包

打开命令控制台,进入您的项目目录,并执行以下命令以下载此捆绑包的最新稳定版本

$ composer require serpstat/sdk

此命令需要您已全局安装 Composer,如 Composer 文档的 安装章节 中所述。

步骤 3: 在应用程序中使用

<?php
require_once __DIR__ . '/../vendor/autoload.php';

// configure your application
$config = [
    'token' => '19666fc1ae1724da1d5ea2f3a99d5f5a',
];

$domain = 'example.com';
$keywords = 'keywords';
$url = 'http://example.com/page1/';

// init client with your serpstat api token
$apiClient = new \Serpstat\Sdk\Core\ApiGuzzleHttpClient($config['token']);

// create instance of any api method class
// e.g. DomainKeywordsMethod
// list of methods classes in folder src\Methods
$apiMethod = new \Serpstat\Sdk\Methods\DomainKeywordsMethod(
    $keywords, 
    \Serpstat\Sdk\Interfaces\IApiClient::SE_GOOGLE_RU
);

try {
    // try call api method
    $response = $apiClient->call($apiMethod);
} catch (\Exception $e) {
    // catch api error 
    $response = $e->getMessage();
}

SDK API 方法列表

SDK 异常