mmoravac/openx

OpenX v4 oAuth API的现代PHP客户端

dev-master 2020-10-28 17:59 UTC

This package is auto-updated.

Last update: 2024-09-29 02:39:27 UTC


README

使用Guzzle v4.xoauth-subscriber插件

安装

php composer.phar require mmoravac/openx

在代码中使用

// Setup client and login with user
$client = new mmoravac\OpenX($consumerKey, $consumerSecret, $oauthRealm, 'http://ox-ui.example.com/ox/4.0/');
$client->login('user@example.com', 'souper-seekret-password');

// GET /account - for list of accounts
$res = $client->get('account');
var_dump($res->json());

你应该能看到账户端点的JSON输出。你可以自由地发出你想要的任何其他请求。

务必阅读OpenX API v4文档

制作HTTP请求

OpenX客户端通过代理所有常规的get/post/put/delete等请求,并在发送请求前自动添加所需的Cookie头部。

// Makes normal request with necessary Cookie header
$res = $client->get('account');

访问Guzzle客户端

如果您需要获取基础Guzzle对象以发出任何进一步请求或进行修改,您可以

// Returns the main GuzzleHttp\Client object
$guzzle = $client->getClient();

请注意,如果您这样做,所需的Cookie头部将不会自动附加到您的请求中,因此您需要自己使用$client->getAuthCookie()来完成此操作。

使用示例

运行提供的example.php的步骤

  1. composer install --dev
  2. cp .env.example .env
  3. 编辑.env以添加OAuth消费者密钥和密钥、用户/密码等。
  4. 运行它:php example.php