1. Go to this page and download the library: Download adiafora/php-api-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adiafora / php-api-client example snippets
composer
//Example
$api = new MyApiClient('POST', ['name' => 'Sergey']);
// or
$api = new MyApiClient();
$response = $api->send();
use Adiafora\ApiClient\AbstractApiClient;
class WebmasterApiClient extends AbstractApiClient
{
private $resource;
private $token;
private $userId;
public function __construct(string $resource, string $method, array $params = [])
{
parent::__construct($method, $params);
$this->resource = $resource;
$this->userId = USER_ID;
$this->token = TOKEN;
}
public function getHeaders(): array
{
return [
'Authorization: OAuth ' . $this->token,
'Accept-Language: ru',
'Content-Type: application/json; charset=utf-8'
];
}
public function getUrl(): string
{
return 'https://api.webmaster.yandex.net/v4/user/' . $this->userId . '/' . $this->resource;
}
}