Download the PHP package abhishekbhardwaj/twitter-api-php without Composer
On this page you can find all versions of the php package abhishekbhardwaj/twitter-api-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abhishekbhardwaj/twitter-api-php
More information about abhishekbhardwaj/twitter-api-php
Files in abhishekbhardwaj/twitter-api-php
Package twitter-api-php
Short Description Simple PHP wrapper for Twitter v1.1 API. Uses Guzzle!
License MIT
Homepage https://github.com/abhishekbhardwaj/Twitter-API-PHP
Informations about the package twitter-api-php
Simple PHP Wrapper for Twitter API v1.1
Twitter-API-PHP is a simple PHP wrapper library for Twitter API v1.1 calls. It has been designed for making the Twitter API as simple to use as possible for developers (on the server or on the client).
It supports:
- Application-Only Authentication (Oauth 2.0).
- Single-User OAuth (Oauth 1.0a).
- 3-legged Authorization (Oauth 1.0a).
Installation
To install via Composer, add the following to your composer.json file and run composer install
:
Dependencies
Basic Usage
Some examples are located in the examples/
directory:
- appExample.php: Example of Application-Only Authentication
- userExample.php: Example of 3-legged Authorization
Detailed explanation can be found below:
To use Twitter as an application:
-
Create an instance of
Twitter\Config\AppCredentials
class with appropriate API keys. -
Create an instance of
Twitter\Client
with theAppCredentials
object you just created. -
Create an Application Connection to Twitter.
-
When using Twitter as an application, you need to use a Bearer Token which can be generated by calling the
createBearerToken()
function. -
Now you can send GET requests (since you can only GET as an application from Twitter) to Twitter. [Details available here!]{https://dev.twitter.com/oauth/application-only}
- Since we use Guzzle internally to talk to Twitter, the
$response
object is an instance ofGuzzleHttp\Message\ResponseInterface
and thus, it has many helpful functions for example:
For more on Guzzle, refer to its official documentation here.
To use Twitter as a user:
this section shows you how to login as a user
-
create an instance of
Twitter\Config\UserCredentials
class with appropriate API keys. -
Create an instance of
Twitter\Client
with theUserCredentials
object you just created. -
Create a User Connection to Twitter.
-
Get Authorization URL.
-
Redirect the user to that URL.
-
Once the user logs in, Twitter will redirect the user back to the callbackUrl you specified in your app settings and in the credentials above.
-
The callback url will get a temporary oauthToken and oauthVerifier as query parameters. Use them to generate an access token (token and secret):
-
$accessTokens
is an assoc-array which containsoauth_token
andoauth_token_secret
which basically never expire. You can store these in the db. - Now you send either GET or POST requests to Twitter on behalf of the authenticated user to the endpoints.
GET
ting from an endpoint:
POST
ing to an endpoint:
Uploading pictures with a Tweet:
A maximum of 4 pictures can be attached to a tweet. To do so:
The list of pictures that is passed on to uploadMedia()
can be URL's or absolute file paths.
Todo
- Change namespace to something other than
Twitter\*
- More documentation.
Changelog
- November 12, 2014:
Version 1.1.2
- Parameters are now optional on GET requests. - November 9, 2014:
Version 1.1.*
- more stable and also lets you upload images to Twitter. - November 8, 2014:
Version 1.0.*
- very first version of the library, didn't have support for media uploads.
Important Links
- All Twitter API Endpoints can be found here.
- All Twitter Authentication related stuff can be found here.
Contribution
If you find any bugs, either post an issue or pull request are always welcome! :)
License
This library is licensed under the MIT License. See the LICENSE
file for more details!
All versions of twitter-api-php with dependencies
guzzlehttp/guzzle Version ~5.0
guzzlehttp/oauth-subscriber Version ~0.2