proapis/proapis-client

访问 https://proapis.cloud 的 API 服务用的 PHP SDK。

1.0.2 2020-06-06 05:13 UTC

README

这是用于从 ProAPIs.cloud 消费 API 服务的 PHP SDK。您可以使用 composer 需求此包,或者从这里下载 ZIP 文件以将其包含到您的项目中。

安装

composer require proapis/proapis-client

入门

首先在 https://proapis.cloud 获取您的 API 密钥。然后,将自动加载文件包含到您的项目中。

require "vendor/autoload.php";

Google SERPs (文档)

use Proapis\Services\GoogleSerps;

// Set your API key
$apiKey = "######################";

// Create instance
$gs = new GoogleSerps($ApiKey);

// Get data
$params = [
    "q" => "Your search query",
    "pages" => 10,
    "hl" => "en_US",
    "gl" => "us",
    "ua" => "desktop"
];
$data = $gs->getData($params);

Google Play (文档)

use Proapis\Services\GooglePlay;

// Set your API key
$apiKey = "######################";

// Create instance
$gp = new GooglePlay($ApiKey);

// Get data
$params = [
    "package" => "com.whatsapp"
];
$data = $gp->getData($params);

关键词数据 (文档)

use Proapis\Services\Keywords;

// Set your API key
$apiKey = "######################";

// Create instance
$kp = new Keywords($ApiKey);

// Get data
$params = [
    "keyword" => "hiking shoes"
];
$data = $kp->getData($params);

Moz 数据 (文档)

use Proapis\Services\Moz;

// Set your API key
$apiKey = "######################";

// Create instance
$moz = new Moz($ApiKey);

// Get data
$data = [
    "domains" => ["google.com", "facebook.com", "wikipedia.org"]
];
$data = $moz->getData($data);

捕获异常

API 客户端根据遇到的错误抛出几个异常。以下是捕获异常并适当处理的方法。

use Proapis\Services\GoogleSerps;
use Proapis\Exceptions\ApikeyException;
use Proapis\Exceptions\CreditsException;
use Proapis\Exceptions\InvalidkeyException;
use Proapis\Exceptions\ServerException;
use Proapis\Exceptions\ValidationException;

// Set your API key
$apiKey = "######################";

// Create instance
$gs = new GoogleSerps($ApiKey);

// Get data
$params = [
    "q" => "Your search query",
    "pages" => 10,
    "hl" => "en_US",
    "gl" => "us",
    "ua" => "desktop"
];

try
{
    $data = $gs->getData($params);
    print_r($data);
} catch(ApikeyException $e) 
{
    // API key not provided
} catch(CreditsException $e)
{
    // Credits exhausted. Buy more at https://proapis.cloud
} catch(InvalidkeyException $e)
{
    // API key is invalid
} catch(ServerException $e)
{
    // Our servers are down. Maybe for maintenance
} catch(ValidationException $e)
{
    // Validation errors occured
    print_r($e->getMessage());
}

问题 & 缺陷

对于常见的缺陷报告,请使用问题。对于与安全相关的问题,请通过 https://proapis.cloud/contact-us 联系我们。