承接 legionth/serin 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

legionth/serin

Composer 安装命令:

composer require legionth/serin

包简介

Asynchronous Twitter API Client built on top of ReactPHP

README 文档

README

Serin is an asynchronous Twitter API CLient built on top of ReactPHP

Table of Contents

Quickstart

useReact\EventLoop\Factory;

require_once __DIR__ . '/../vendor/autoload.php';

$loop = Factory::create();

$oauthConsumerKey = 'SyCz6mFj7992Wy9tAcM1zQQci';
$consumerSecret = 'm349wE5VEkS3PM2FdS5eeptxoXz4o6jPHVyS1JVpGCZmYyPMqf';

$oauthToken = '3019738408-5wkZjXGk02TfyjWpMMolQHHdkQ3fr8APdkkTluk';
$tokenSecret = 'bo34Dph9tQGQC7cEk7ZBir5f9Du608FylevCAUwzw33sG';

$client = new \Legionth\Serin\Client(
    $loop,
    $oauthConsumerKey,
    $consumerSecret,
    $oauthToken,
    $tokenSecret
);

$response = $client->tweet('does this work?');

$response->then(function (\Psr\Http\Message\ResponseInterface $response) use ($client) {
    echo \RingCentral\Psr7\str($response);
}, function (Exception $exception) {
    echo(\RingCentral\Psr7\str($exception->getResponse()));
});

$loop->run();

The code above will create a tweet on the designated account.

What is different from other libraries?

While other Twitter API Clients written in PHP use extension like Curl to send HTTP Requests, this library uses 100% pure PHP instead. The usage of ReactPHP is used to make this library entirely asynchronous.

How to use this library

The Client class is all needed to communicate with Twitter API. Just enter the Twitter secrets and tokens and use the Client to interact with Twitter.

Never used the Twitter API before? Use the official Twitter Developer Guide to create the tokens and secrets needed for this library.

This library uses ReactPHP so the entire library is based on a non-blocking concept. That's why every Client method will Return a Promise which will result in an PSR-7 Response when the server answered the request. In the meantime other requests can be sent without waiting for previous ones to be finished (unless you want to :) ).

$response = $client->tweet('does this work?');
$responseSecondTweet = $client->tweet('of course it does');

$response->then(function (\Psr\Http\Message\ResponseInterface $response) use ($client) {
    echo \RingCentral\Psr7\str($response);
}, function (Exception $exception) {
    echo(\RingCentral\Psr7\str($exception->getResponse()));
});

$responseSecondTweet->then(function (\Psr\Http\Message\ResponseInterface $response) use ($client) {
    echo \RingCentral\Psr7\str($response);
}, function (Exception $exception) {
    echo(\RingCentral\Psr7\str($exception->getResponse()));
});

Endpoints

Have a look at the Client methods to get an overview of all possible endpoints. This library tried to be as near as possible on the actual wording of the offical Twitter API.

Custom Requests

Is some endpoint missing? No worries create a PSR-7 request containing all necessary data.

The client will authenticate your request with the required OAuth 1.0a authentication.

$client = new \Legionth\Serin\Client(
    $loop,
    $oauthConsumerKey,
    $consumerSecret,
    $oauthToken,
    $tokenSecret
);

$request = new RingCentral\Psr7\ServerRequest(
    'POST',
    'https://api.twitter.com/1.1/statuses/update.json',
    [ 'Content-Type' => 'application/x-www-form-urlencoded'],
    'status=' . rawurlencode('Hello World'),
);

$response = $client->tweet($request);

Do you want to have an endpoint in the library? Open up a Pull Request or contact me!

Authentication

The OAuth 1.0a Authentication in this library will be used to send tweets, retweeting and get status information. That is why a registration at the Twitter API is required in order to use this library.

Install

The recommended way to install this library is through Composer.

New to Composer?

This will install the latest supported version:

$ composer require legionth/serin:^0.1.0

License

See License file

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固