Artax based client for Twitter API
This project provides a crude Twitter OAuth client for AMPHP based applications. It utilizes the Artax asynchronous HTTP client while wrapping the Abraham Twitter OAuth library to properly format the request.
Utilizing the Abraham Twitter OAuth library is a preliminary step until the library can properly implement Twitters OAuth request. Until that time, signatures will be generated with blocking code. It should not be too terrible as the signature only uses a SHA1 HMAC.
Add the library via composer:
composer require aenglander/artax-twitter-oauth
To use the library, create a request factory using the credentials from your Twitter Application's Key and Access Tokens tab in the Twitter Developer applications site https://apps.twitter.com:
$requestFactory = new AEnglander\ArtaxTwitterOAuth\RequestFactory( "ConsumerKeyGoesHere", "ConsumerSecretGoesHere", "AccessTokenGoesHere", "AccessTokenSecretGoesHere" );
Then create an Artax request for the appropriate API path:
$request = $requestFactory->createRequest('GET', 'statuses/home_timeline.json');
The previous example will get the current home time line for the user who owns the Twitter application.
Once you have the request, you can now use it with the Artax Client:
$client = new Amp\Artax\Client(); $promise = $client->request($request); $response = \Amp\wait($promise); printf( "\n%d %s\n%s\n", $response->getStatus(), $response->getReason(), $response->getBody() );
The above response will execute the request and print out the result.