meniam / admitad-php-api
Admitad API 库
0.1.5
2019-01-09 11:49 UTC
Requires
- php: >=5.3.0
- kriswallsmith/buzz: >=v0.10 <=0.16.1
- psr/log: ~1.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-13 12:56:49 UTC
README
Admitad API 的 PHP 封装
安装
安装 https://getcomposer.org.cn/ 并运行以下命令
php composer.phar require admitad/api dev-master
示例
请求访问令牌
- 通过用户名 / 密码
$api = new Admitad\Api\Api() $response = $api->authorizeByPassword($clientId, $clientPassword, $scope, $username, $password); $result = $response->getResult(); // or $response->getArrayResult();
- OAuth2
// 1 step - get oauth authorization url $api = new Admitad\Api\Api(); $authorizeUrl = $api->getAuthorizeUrl($clientId, $redirectUri, $scope); // redirect user to authorizeUrl // 2 step - request access token by OAuth2 code returned from authorization url $response = $api->requestAccessToken($clientId, $clientSecret, $code, $redirectUri); $result = $response->getResult();
- 签名请求(适用于 apps.admitad.com 上的应用程序)
$api = new Admitad\Api\Api(); $data = $api->parseSignedRequest($signedRequest, $clientSecret); // this method throws Admitad\Api\Exception\InvalidSignedRequestException when $signedRequest is invalid
刷新令牌
$result = $api->refreshToken($clientId, $clientSecret, $refreshToken)->getResult();
方法
与 API 通信有 2 种常用方法
$api = new Admitad\Api\Api($accessToken); $api->get($path, $params); $api->post($path, $params); //for example $data = $api->get('/advcampaigns/', array( 'limit' => 20, 'offset' => 0 ))->getResult();
分页结果方法可以按这种方式迭代(而不是手动调用不同偏移量的方法)
$iterator = $api->getIterator('/advcampaigns/', array( 'order_by' => 'id' )); foreach ($iterator as $campaign) { // do smth with campaign }