PHP code example of docaxess / php-apify-sdk

1. Go to this page and download the library: Download docaxess/php-apify-sdk 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/ */

    

docaxess / php-apify-sdk example snippets


use DocAxess\Apify\ApifyConnector;

$apify = new ApifyConnector('YOUR_APIFY_TOKEN');

$user = $apify->user()->me(); 

use DocAxess\Apify\ApifyConnector;
use DocAxess\Apify\Task\Data\Option\TaskOption;

// The ID of the actor you want to run, it can be found in the actor's URL
// or you can use the slug like 'yanis~actor-name'
$actorId = 'YOUR_ACTOR_ID'; 
$apify = new ApifyConnector('YOUR_APIFY_TOKEN');
$run = $apify->taskRunner()->run($actorId);

// it also possible to pass configuration options and input data
$config = new TaskOption(
    build: '1.2.3', 
    timeout: 300, 
    memory: 2048, 
);
$run = $apify->taskRunner()->run($actorId, $config, [
    'key' => 'value' // input data to pass to the actor run
]);

use DocAxess\Apify\ApifyConnector;
use DocAxess\Apify\Task\Data\Option\TaskOption;
use DocAxess\Apify\Webhook\Config\WebhookConfig;
use DocAxess\Apify\Webhook\Event\EventType;

$actorId = 'YOUR_ACTOR_ID'; 
$apify = new ApifyConnector('YOUR_APIFY_TOKEN');

$config = new TaskOption();
$config->addWebhook(WebhookConfig::forEvent(EventType::RUN_SUCCEEDED, 'https://your-webhook-url.com'));

$run = $apify->taskRunner()->run($actorId, $config);

use DocAxess\Apify\Webhook\Data\EventResult;

$eventResult = EventResult::fromArray(request()->all());

use DocAxess\Apify\ApifyConnector;
use DocAxess\Apify\Webhook\Data\EventResult;
use DocAxess\Apify\Core\Type\Identifier;

$eventResult = EventResult::fromArray(request()->all());

$apify = new ApifyConnector('YOUR_APIFY_TOKEN');
$results = $apify->dataset()->getJson($eventResult->datasetId);

// or if you know the dataset ID
$results = $apify->dataset()->getJson(Identifier::make('YOUR_DATASET_ID'));

use DocAxess\Apify\ApifyConnector;
use DocAxess\Apify\Webhook\Data\EventResult;
use DocAxess\Apify\Core\Type\Identifier;

$apify = new ApifyConnector('YOUR_APIFY_TOKEN');
$results = $apify->dataset()->getJson(Identifier::make('YOUR_DATASET_ID'), YourDtoForItem::class);
bash
composer