PHP code example of megaads / apify-client-php

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

    

megaads / apify-client-php example snippets


use Megaads\ApifyClient\Client;

$query = Client::endpoint("product", [
    Client::OPTION_API_HOST => "https://api.domain.com",
    Client::OPTION_API_AUTH => "token=dsfqwe123sdf2342c",
    Client::OPTION_REQUEST_HEADER => ["Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"]
]);

$query->addField("customer_id", 123);

$query->addField("version", "1.0.0");

$query->toURL();

$query->pageId(0);

$query->pageSize(100);

$query->sort("user_id");

$query->sort("-created_at");

$query->sort(["user_id", "-created_at"]);

$query->select("id");

$query->select(["content", "user_id", "sum(view_count) as view_sum"]);

$query->select(["user_id", "sum(view_count) as view_sum"]);

$query->group("user_id");

$query->embed("cities");

$query->embed(["nation", "districts"]);

$query->filter("nation.location_code", Client::SELECTION_EQUAL, "EU");

$query->filter("districts.name", Client::SELECTION_LIKE, land);

$query->find(1);

$query->get();

[
    "meta" => [
        "has_next" => true,
        "total_count" => 100,
        "page_count" => 2,
        "page_size" => 50,
        "page_id" => 0
    ],
    "result" => [],
    "status" => "successful"
]

[    
    "result" => [],
    "status" => "successful"
]

[    
    "result" => 50,
    "status" => "successful"
]

[    
    "result" => 1,
    "status" => "successful"
]

use Megaads\ApifyClient\Client;

$query = Client::request("https://api.domain.com/product", 
Client::METHOD_POST, 
[
    "name" => "Hello",
    "code" => "C0001"
],
[
    "Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l"
]);

$query->select("view_count");

$query->increment();