PHP code example of cloudycity / kuaishou-marketing-sdk

1. Go to this page and download the library: Download cloudycity/kuaishou-marketing-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/ */

    

cloudycity / kuaishou-marketing-sdk example snippets


use CloudyCity\KuaishouMarketingSDK\Auth;

// 获取token
$auth = new Auth(APPID, SECRET);
var_dump($auth->getTokens(AUTH_CODE));

// 刷新token
var_dump($auth->refreshTokens(REFRESH_TOKEN));

$client = new Client(ADVERTISE_ID, TOKEN);
var_dump($client->advertiser->getInfo());

use CloudyCity\KuaishouMarketingSDK\Client;
use App\Services\KuaishouService;

$apps = KuaishouService::getApps();

// 遍历开发者应用
foreach ($apps as $app) {

    $service = new KuaishouService($app['id'], $app['secret']);
    $advertiserIds = $service->getAdvertiserIds();

    // 遍历应用下授权的广告主
    foreach ($advertiserIds as $advertiserId) {
        $tokens = $service->getTokenByCache($advertiserId);
        $client = new Client($tokens['advertiser_id'], $tokens['access_token']);

        // 处理业务逻辑
        try {
            $result = $client->advertiser->getFunds();
        } catch(\Exception $e) {
            //
        }
    }
}