Download the PHP package saturn/twarpy without Composer
On this page you can find all versions of the php package saturn/twarpy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download saturn/twarpy
More information about saturn/twarpy
Files in saturn/twarpy
Package twarpy
Short Description A simple and small PHP library for accessing the Twitter REST API
License GPL-2.0
Homepage https://github.com/pkrll/Twarpy
Informations about the package twarpy
Twarpy
A simple and small PHP library for accessing Twitter's REST API (v1.1) using 3-Legged OAuth or Application-only tokens.
Requirements
- PHP >= version 5.3.
- Curl extension.
Installation
There are two ways to install Twarpy. If you prefer using composer, just run the following command in the terminal at the root directory of your project:
You can also include it as a dependency in your composer.json file and then run composer update
:
You can also download the source directly and include it in your project directory manually, or clone this repository:
If you've installed Twarpy with Composer, you can use the autoloader:
Usage
- The first step is to register your application with Twitter.
- Copy the consumer key and consumer secret (never share these keys with anyone).
Using 3-Legged OAuth
- Using 3-Legged OAUth flow allows the app to read or post to Twitter on the users behalf. But the user must authenticate each requests.
- To initialize Twarpy with this auth method, you need the previously collected consumer key and secret tokens along with an oauth token and oauth secret. If a user has not authenticated the app, they will be redirected to Twitter.com. Upon authorization, the application will collect the newly granted access token (remember to save the tokens once you've retrieved them by using the method
getAccessToken()
, so that the user does not need to authenticate each request manually). -
Create a new Twarpy object, with an array containing the configuration and a constant representing the auth method:
- Next time you want to make an API call on that users behalf, you can include the retrieved tokens in the
$config
-array:
Using Application-only auth
- The app-only auth method is similarly to the 3-Legged method, but does not require the user to authenticate the application. This auth method does not allow for requests that require user context, like creating or deleting tweets.
- To initialize Twarpy with this auth method, you need the previously collected consumer key and secret tokens.
-
Create the Twarpy object and use the constant
APP_ONLY
as the second parameter: - Save the access token for faster requests and include in the
$config
-array with the keyaccess_token
(please note, this method does not require a secret token).
Making requests
Making requests to the Twitter API is supereasy. All you need is the http method (GET/POST), the api path and, if needed, a parameters array. Consult the Twitter API documentation for available requests.
Example request
Author
- Twarpy is brain child of Ardalan Samimi.