vlucas/openx-oauth-client

此软件包最新版本(v1.0.0)没有可用的许可信息。

OpenX v4 oAuth API的现代PHP客户端

v1.0.0 2014-11-04 17:05 UTC

This package is auto-updated.

Last update: 2024-09-08 12:01:40 UTC


README

使用 Guzzle v4.xoauth-subscriber 插件

安装

php composer.phar require vlucas/openx-oauth-client

在您的代码中使用

// Setup client and login with user
$client = new Vlucas\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