apple-ads-php-demo

Apple Ads Campaign Management API, OAuth, Report API examples.

邀请 API 用户

上传 Public Key

// composer install require "vendor/autoload.php"; use LcobucciJWTConfiguration; use LcobucciJWTSignerEcdsaSha256; use LcobucciJWTSignerKeyInMemory; // 1. Create a Client Secret $config = Configuration::forSymmetricSigner( Sha256::create(), InMemory::file(__DIR__ . '/private-key.pem') ); $client_id = 'SEARCHADS.c99b2f21-5964-4869-847c-ljh799004501'; $team_id = 'SEARCHADS.c99b2f21-5964-4869-847c-ljh799004501'; $key_id = '285e95c1-d514-4522-b6e3-ljh799004501'; $audience = "https://appleid.apple.com"; $alg = "ES256"; $now = new DateTimeImmutable(); $token = $config->builder() ->issuedBy($team_id) ->permittedFor($audience) ->issuedAt($now) ->relatedTo($client_id) ->expiresAt($now->modify('+180 days')) ->withHeader('alg', $alg) ->withHeader('kid', $key_id) ->getToken($config->signer(), $config->signingKey()); $client_secret = $token->toString(); echo "clientSecret 建议保存,有效期可设置最长 180 天n"; echo $client_secret; echo "n"; // 2. Request an Access Token $postdata = http_build_query( array( 'grant_type' => 'client_credentials', 'scope' => 'searchadsorg', 'agency' => 'ljh', 'client_id' => $client_id, 'client_secret' => $client_secret ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencodedrn". "Host: appleid.apple.comrn", 'content' => $postdata ) ); $context = stream_context_create($opts); $contents = file_get_contents('https://appleid.apple.com/auth/oauth2/token', false, $context); $results = json_decode($contents); echo "access_token 有效期1个小时n"; echo $results->access_token; echo "n"; // 3. Get User ACL $opts = array('http' => array( 'method' => 'GET', 'header' => "Authorization: Bearer ".$results->access_token ) ); $context = stream_context_create($opts); $contents = file_get_contents('https://api.searchads.apple.com/api/v4/acls', false, $context); echo $contents; echo "n";

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。