marketingtoolbox/dataforseo-php-sdk

PHP library for the DataForSEO API

0.1.0 2024-04-01 17:32 UTC

This package is not auto-updated.

Last update: 2024-05-01 09:11:01 UTC


README

Latest Version Software License Build Status Code Coverage Mutation testing

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');