ipalaus / buffer-php-sdk
PHP的Buffer非官方SDK。
Requires
- php: >=5.3.0
- guzzle/guzzle: 3.x
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-09-24 00:57:33 UTC
README
PHP的Buffer非官方SDK。
此包符合PSR-0、PSR-1和PSR-2。如果您注意到任何符合性疏忽,请通过pull request发送补丁。
安装
通过Composer
{ "require": { "ipalaus/buffer-php-sdk": "1.1.*" } }
用法
首先,您需要一个有效的令牌,以便能够向Buffer API发送授权请求。您可以在注册您的应用程序并使用提供的访问令牌,或者通过OAuth 2.0进行认证来获取用户的令牌。
一旦您有了有效的令牌,您就可以创建一个新的TokenAuthorization
实例,然后创建一个Client
实例
use Ipalaus\Buffer\Client; use Ipalaus\Buffer\TokenAuthorization; $auth = new TokenAuthorization('access_token'); $client = new Client($auth);
方法
用户
用户代表单个Buffer用户帐户。
获取用户
返回单个用户。
$user = $client->getUser();
配置文件
Buffer配置文件代表与单个社交媒体帐户的连接。
获取配置文件
返回与用户帐户连接的社交媒体配置文件数组。
$profiles = $client->getProfiles();
获取单个配置文件
返回单个指定社交媒体配置文件的详细信息。
$client->getProfile($id);
获取发布计划
返回与社交媒体配置文件关联的发布计划详细信息。
$client->getProfileSchedules($id);
设置发布计划
为指定的社交媒体配置文件设置发布计划。
use Ipalaus\Buffer\Schedule; $schedule = new Schedule; // you can pass a single string or an array $schedule->addDay('mon'); $schedule->addDay(array('tue', 'wed')); // same for time $schedule->addTime('09:00'); $schedule->addTime(array('12:00', '15:00')); $client->updateProfileSchedules('id', $schedule); // alternative syntax, even shorter $schedule = new Schedule(array('mon', 'tue', 'wed'), array('09:00', '12:00', '15:00')); $client->updateProfileSchedules($id, $schedule); // multiple schedules $weekdays = new Schedule(array('mon', 'tue', 'wed', 'thu', 'fri'), array('09:00', '12:00', '16:00'); $weekends = new Schedule(array('sat', 'sun'), array('12:00', '18:00'); $client->updateProfileSchedules($id, array($weekdays, $weekends));
注意:更新多个计划仅适用于付费计划。不幸的是,如果我们尝试在免费计划中更新多个计划,它将简单地删除所有内容。
更新
更新代表单个社交媒体帐户的单个帖子。更新还可以包括媒体附件,如图片和链接。
获取更新
返回单个社交媒体更新。
$client->getUpdate('id');
获取待处理更新
返回一个数组,包含单个社交媒体配置文件缓冲区中的更新。
$client->getProfilePendingUpdates('id'); // optional parameters $client->getProfilePendingUpdates($id, $page = null, $count = null, $since = null, $utc = false)
$page integer
指定要接收的状态更新页面。如果未指定,将返回结果的第一页。$count integer
指定要接收的状态更新数量。如果提供,必须在1到100之间。$since integer
指定一个Unix时间戳,只有在此时间之后创建的状态更新才会被检索。$utc boolean
如果utc设置为true,则时间将以UTC相对于用户的关联时区返回。
获取已发送更新
返回单个社交媒体配置文件已从缓冲区发送的更新数组。
$client->getProfileSentUpdates($id); // optional parameters $client->getProfileSentUpdates($id, $page = null, $count = null, $since = null, $utc = false);
$page integer
指定要接收的状态更新页面。如果未指定,将返回结果的第一页。$count integer
指定要接收的状态更新数量。如果提供,必须在1到100之间。$since integer
指定一个Unix时间戳,只有在此时间之后创建的状态更新才会被检索。$utc boolean
如果utc设置为true,则时间将以UTC相对于用户的关联时区返回。
获取更新交互
返回对社交媒体更新进行的单个交互的详细信息,例如收藏、转发和点赞。
$client->getUpdateInteractions($id); // optional parameters $client->getUpdateInteractions($id, $page = null, $count = null, $event = null);
$page integer
指定要接收的交互页面。如果未指定,将返回结果的第一页。$count integer
指定要接收的交互数量。如果提供,必须在1到100之间。$event 字符串
指定要检索的事件类型,例如 "retweet","favorite","like","comment","mention" 或 "share"。它们也可以是复数形式(例如,"shares")。复数形式除了视觉语义外没有其他影响。
注意:我认为这个端点存在一个bug。我需要深入挖掘以找出原因。
重排更新
编辑指定社交媒体配置文件状态发送到缓冲区的顺序。
$client->reorderProfileUpdates($id, array($update1, $update3, $update5)); // optional parameters $client->reorderProfileUpdates($id, $order, $offset = null, $utc = false)
$order 数组
状态更新 ID 的有序数组。这可以与偏移量参数结合使用作为部分数组,或作为配置文件缓冲区中每个更新的完整数组。$offset 整数
指定要接收的状态更新数量。如果提供,必须在 1 到 100 之间。$utc boolean
如果utc设置为true,则时间将以UTC相对于用户的关联时区返回。
随机化更新顺序
随机化指定社交媒体配置文件状态发送到缓冲区的顺序。
$client->shuffleProfileUpdates($id); // optional parameters $client->shuffleProfileUpdates($id, $count = null, $utc = false);
$count 整数
指定返回的状态更新数量。这些将对应于将发布的第一个状态更新。$utc boolean
如果utc设置为true,则时间将以UTC相对于用户的关联时区返回。
创建更新
创建一个或多个新的状态更新。
use Ipalaus\Buffer\Update; $update = new Update; $update->text = 'Check out my website!'; $update->addProfile($id); $update->shorten = 'false'; // optional, default: true $update->now = 'false'; // optional, default: true $update->top = 'true'; // optional, default: false $update->attachment = 'false'; // optional, default: true // adding media is optional, available options: link, description, picture, thumbnail $update->addMedia('link', 'http://ipalaus.com'); $update->addMedia('description', 'Isern Palaus personal website.'); $update->addMedia('picture', 'http://ipalaus.com/img/isern-palaus_smile.jpg'); $update->addMedia('thumbnail', 'http://ipalaus.com/img/isern-palaus_smile.jpg'); // required with picture // schedule a update is optional $update->schedule(time() + 3600); // you can use timestamp $update->schedule('2013-12-23 12:03:23'); // or a valid date/time string $client->createUpdate($update);
Update::$text 字符串
状态更新文本。- 配置文件 应发送状态更新的配置文件 ID。无效的 profile_id 将被静默忽略。
Update::$shorten 布尔值
如果 shorten 为 false,则文本中的链接将不会自动缩短,否则会。Update::$now 布尔值
如果 now 被设置,则此更新将立即发送到所有配置文件而不是被添加到缓冲区。Update::$top 布尔值
如果 top 被设置,则此更新将被添加到缓冲区的顶部,并成为下一个发送的更新。- 媒体 要附加到更新的媒体,目前接受链接、描述和图片参数。
- 调度 描述更新应发布时间的日期。将覆盖任何 top 或 now 参数。
更新更新
编辑现有单个状态更新。
$update = new Update; $update->text = 'Lorem ipsum'; // required $client->updateUpdate($id, $update);
Update::$text 字符串
状态更新文本。Update::$now 布尔值
如果 now 被设置,则此更新将立即发送到所有配置文件而不是被添加到缓冲区。- 媒体 要附加到更新的媒体,目前接受链接、描述和图片参数。
- 调度 描述更新应发布时间的日期。将覆盖任何 top 或 now 参数。
分享更新
立即分享单个挂起更新并重新计算队列中剩余更新的时间。
$client->shareUpdate($id);
删除更新
永久删除现有状态更新。
$client->destroyUpdate($id);
将更新移至顶部
将现有状态更新移至队列顶部并重新计算队列中所有更新的时间。返回带有其新发布时间的更新。
$client->moveUpdateToTop($id);
链接
链接代表通过 Buffer 分享的唯一 URL。
分享
返回一个对象,其中包含使用 Buffer 分享的链接的分享次数。 www 将被移除,但其他子域不会。
$client->getLinkShares('http://ipalaus.com');
信息
此命名空间用于创建您的应用程序时可能有用的辅助信息。
获取配置
返回一个对象,其中包含 Buffer 当前使用的配置,包括支持的服务、它们的图标以及字符和计划的不同限制。
服务键直接映射到配置文件和更新上的那些键,这样您就可以轻松显示正确的图标或计算更新的正确字符长度。
$client->getConfigurationInfo();
Buffer 按钮
您还可以使用 SDK 生成一个 Buffer 按钮
use Ipalaus\Buffer\Button; // available count styles: vertical, horizontal or none echo Button::create('vertical'); // our even simpler echo Button::vertical(); // optional parameters Button::create($style, $tweet = null, $url = null, $username = null, $picture = null);
$style 字符串
计数器的位置,选项:垂直、水平或无。$tweet 字符串
空白以使用按钮所在的页面的标题。$url 字符串
空白以使用按钮所在页面的 URL。$username 字符串
要提及的 Twitter 用户名。$picture 字符串
要分享的图片的 URL(可选)。
支持
错误和功能请求在 GitHub 上跟踪。
许可
本软件包采用MIT许可证发布。有关详细信息,请参阅随附的LICENSE文件。