docaxess/php-apify-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

docaxess/php-apify-sdk

最新稳定版本:1.0.4

Composer 安装命令:

composer require docaxess/php-apify-sdk

包简介

Unofficial SDK for Apify service

README 文档

README

Latest Version CC-BY-1.0 License

CI Testing

Installation

composer require docaxess/php-apify-sdk

Token generation

You can generate a token by following the instructions:

  • Go to the Apify Console
  • Go to settings > Integrations
  • Click on the "+ Add token" button

You can find more detail on the Apify Documentation

Usage

First you need to create a new instance of the ApifyConnector class and pass your token as a parameter.

use DocAxess\Apify\ApifyConnector;

$apify = new ApifyConnector('YOUR_APIFY_TOKEN');

From this point you can use the different methods available in the class.

Get information about the user

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

Start a new actor run

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

Add a webhook to an actor

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 = $config->addWebhook(WebhookConfig::forEvent(EventType::RUN_SUCCEEDED, 'https://your-webhook-url.com'));

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

Webhook events detail can be parsed with the provided object.

use DocAxess\Apify\Webhook\Data\EventResult;

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

Get Dataset

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

By default, the dataset will return associative array, but you can also give the DTO class to return for each item. It should implement the DocAxess\Apify\Dataset\Item\Item interface.

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

Disclaimer

Affiliation

This package is not an official package from Apify. It is a community package that uses the Apify API. It is not affiliated with Apify in any way.

API Coverage

This package does not cover all the Apify API, and was primarily built to cover our own use cases. It is a work in progress and will be updated over time. If you need a specific feature, feel free to open an issue or a pull request.

统计信息

  • 总下载量: 1.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: CC-BY-1.0
  • 更新时间: 2024-05-31