nmrkt/linkshare

消费 Linkshare API 的 Guzzle 客户端

dev-master 2015-09-03 14:46 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:18:20 UTC


README

Build Status

消费 Linkshare API 的 Guzzle 客户端

工作原理

此库使用 OAuth 插件:[https://github.com/NMRKT/guzzle5-oauth2-subscriber](https://github.com/NMRKT/guzzle5-oauth2-subscriber) 订阅 Guzzle 客户端调用,并确保您的客户端请求包含正确的 "Authorization" 标头。

目前仅构建了一个用于 事件 API 的客户端。如果有人想处理高级报告、优惠券、产品搜索等端点,欢迎提交拉取请求。

非常重要:在您的配置中设置 'grant_type' => 'password' - 否则,OAuth 插件将其设置为 'client_credentials',Linkshare 将不知道这意味着什么。

您可以通过点击“显示密钥”按钮在此处找到您的 client_idclient_secret:[https://developers.rakutenmarketing.com/subscribe/site/pages/subscriptions.jag](https://developers.rakutenmarketing.com/subscribe/site/pages/subscriptions.jag)

用法

<?php

use Nmrkt\Linkshare\Client\Events;

$config = [
    'grant_type' => 'password',
    'username' => 'your_linkshare_username',
    'password' => 'your_linkshare_password',
    'client_id' => 'your client id',
    'client_secret' => 'your client secret',
    'scope' => 'your scope(s)', // optional
];
//initialize the client with your API config
$client =  new Events($config);
//create the oauth subscirber
$subscriber = $client->getOauth2Subscriber();
//attach the oauth subscriber to the client
$client->attachOauth2Subscriber($subscriber);

// Now you can set params using the convenience methods following the 
$client->setProcessDateStart('2014-05-30 12:00:00');
$client->setLimit(1000);
//execute the query to the API
$transactions = $client->getTransactions();

###等等,为什么我要自己附加订阅者……这是为了使库可以与模拟隔离和测试。