marketingtoolbox / dataforseo-php-sdk
PHP library for the DataForSEO API
0.1.0
2024-04-01 17:32 UTC
Requires
- php: >=8.1
- cuyz/valinor: ^1.3
- league/uri: ^7.3
- php-http/discovery: ^1.19
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1
- psr/http-factory: ^1.0
- psr/http-factory-implementation: ^1
- symfony/string: ^6.0 || ^7.0
- webmozart/assert: ^1.11
Requires (Dev)
- infection/infection: ^0.26
- nyholm/psr7: ^1.8
- phpspec/prophecy-phpunit: ^2.2
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.18
- setono/code-quality-pack: ^2.7
- symfony/http-client: ^6.0 || ^7.0
This package is not auto-updated.
Last update: 2024-11-13 11:52:20 UTC
README
Installation
composer require marketingtoolbox/dataforseo-php-sdk
Usage
Here's an example of how to use the library with the SERP > Google > Organic endpoint:
<?php use MarketingToolbox\DataForSEO\Request; use MarketingToolbox\DataForSEO\Response; // Let's start by initializing the client $client = new MarketingToolbox\DataForSEO\Client\Client('your_login', 'your_password'); // Now we can use the client to make requests // Notice that the request objects' namespaces are similar to the API endpoints /** @var Response\Serp\Google\Organic\TaskPostResponse $response */ $response = $client->request(new Request\Serp\Google\Organic\TaskPostRequest( // In the first request we use the pingback url to get notified when the task is finished. // The PingbackUrl value object will create a pingback url including the id and tag query parameters new Request\Serp\Google\Organic\TaskPostRequestData('bikes', 'United States', 'en', 'your_tag', pingbackUrl: (string) new Request\PingbackUrl('https://your-pingback-url.com')), new Request\Serp\Google\Organic\TaskPostRequestData('cars', 'United States', 'en'), )); /** @var Response\Serp\Google\Organic\TaskPostResponseTask $task */ foreach ($response->tasks as $task) { // iterate over each task } // You can also find a task by the tag you provided when you created it /** @var Response\Serp\Google\Organic\TaskPostResponseTask|null $task */ $task = $response->findTaskByTag('your_tag');