PHP code example of phpdie / amazon-ads-api

1. Go to this page and download the library: Download phpdie/amazon-ads-api 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/ */

    

phpdie / amazon-ads-api example snippets




use AmazonAdsApi\Auth;
use AmazonAdsApi\AdsRequest;
use AmazonAdsApi\SponsoredProducts\AdGroups;

class Test{
    public function index(){
        $profileId = '用你的吧';
        $client_id = '用你的吧';
        $client_secret = '用你的吧';
        
        $country_code = 'US';//可以是其他国家

        //通过refresh_token获取access_token和新的refresh_token
        //$refresh_token = '用你的吧';
        //$refresh_token_result = (new Auth)->getAccessTokenByRefreshToken($client_id, $country_code, $client_secret, $refresh_token);
        //print_r(json_decode($refresh_token_result, true));

        $access_token = '上面的代码能拿到access_token';
        $instance = AdsRequest::getInstance($client_id, $country_code, $profileId, $access_token);

        //获取SP广告组
        $list = new AdGroups($instance);
        $result = $list->index();
        print_r(json_decode($result, true));
    }
}