Download the PHP package noweh/twitter-api-v2-php without Composer
On this page you can find all versions of the php package noweh/twitter-api-v2-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package twitter-api-v2-php
Twitter API V2 for PHP
Twitter API V2 is a PHP package which provides an easy and fast access to Twitter REST API for Version 2 endpoints.
Documentation
- Installation
- Github Actions
- Usage
- Active your developer account
- Configuration setup
- API Functionality
- Include the HTTP headers provided by Twitter in the response
- Tweets endpoints
- Timeline endpoints
- Find Recent Mentioning for a User
- Find Recent Tweets for a User
- Reverse Chronological Timeline by user ID
- Tweet/Likes endpoints
- Tweets liked by a user
- Users who liked a tweet
- Tweet/Lookup endpoints
- Search specific tweets
- Find all replies from a Tweet
- Tweet endpoints
- Fetch a tweet by Id
- Create a new Tweet
- Upload image to Twitter (and use in Tweets)
- Tweet/Quotes endpoints
- Returns Quote Tweets for a Tweet specified by the requested Tweet ID
- Retweet endpoints
- Retweet a Tweet
- Tweet/Replies endpoints
- Hide a reply to a Tweet
- Unhide a reply to a Tweet
- Tweet/Bookmarks endpoints
- Lookup a user's Bookmarks
- Timeline endpoints
- Users endpoints
- User/Blocks endpoints
- Retrieve the users which you've blocked
- User/Follows endpoints
- Retrieve the users which are following you
- Retrieve the users which you are following
- Follow a user
- Unfollow a user
- User/Lookup endpoints
- Find me
- Find Twitter Users
- User/Mutes endpoints
- Retrieve the users which you've muted
- Mute user by username or ID
- Unmute user by username or ID
- User/Blocks endpoints
- Contributing
- To run test
- To run code analyzer
Installation
To begin, you'll need to add the component to your composer.json
After adding the component, update your packages using composer update
or install them using composer install
.
Github Actions
This repository uses Github Actions for each push/pull request, employing PHPStan/PHPUnit.
Consequently, with each valid push, a new Tweet is posted from the Twitter test account.
Usage
Active your developer account
Before anything else, you must follow this tutorial.
- Request approval for a developer account;
- Once your developer account is approved, you will need to create a Project;
- Enable read/write access for your Twitter app;
- Generate Consumer Keys and Authentication Tokens;
- Retrieve your Keys and Tokens from the Twitter Developer portal.
Configuration setup
Expected settings are as follows:
By changing the value of 'api_base_uri'
you can have the requests target a different server, for instance, a simulated one, thus making testing your application in isolation easier.
For a quick mock server setup you can use mockoon.
API Functionality
All API calls are triggered when the performRequest()
method is invoked.
Depending on the context, this method can either be empty or contain data that will be sent as PostData (refer to examples of each call below).
Include the HTTP headers provided by Twitter in the response
The performRequest()
method accepts a second parameter, $withHeaders
, which is a boolean value.
Setting this parameter to true
will include the headers information in the response.
Here are some examples of information included in headers:
x-rate-limit-limit
: the rate limit ceiling for that given endpointx-rate-limit-remaining
: the number of requests left for the 15-minute windowx-rate-limit-reset
: the remaining window before the rate limit resets, in UTC epoch seconds
Example:
Free mode
This API can be used in free mode, which allows for a limited usage of the API.
In this mode, the Find me method is the only one that can be used.
You have to set the free_mode
parameter to true
when creating the client.
Example:
Tweets endpoints
Timeline endpoints
Find Recent Mentioning for a User
Example:
Find Recent Tweets for a User
Example:
Reverse Chronological Timeline by user ID
Example:
Tweet/Likes endpoints
Tweets liked by a user
Example:
Users who liked a tweet
Example:
Tweet/Lookup endpoints
Search specific tweets
Example:
Find all replies from a Tweet
Tweet endpoints
Fetch a tweet by Id
Example:
Create a new Tweet
Example:
Upload image to Twitter (and use in Tweets)
Example:
Tweet/Quotes endpoints
Returns Quote Tweets for a Tweet specified by the requested Tweet ID
Example:
Retweet endpoints
Retweet a Tweet
Example:
Tweet/Replies endpoints
Hide a reply to a Tweet
Example:
Unhide a reply to a Tweet
Example:
Tweet/Bookmarks endpoints
Lookup a user's Bookmarks
Example:
Users endpoints
User/Blocks endpoints
Retrieve the users which you've blocked
Example:
User/Follows endpoints
Retrieve the users which are following you
Example:
Retrieve the users which you are following
Example:
Follow a user
Example:
Unfollow a user
Example:
User/Lookup endpoints
Find Me
Example:
Find Twitter Users
findByIdOrUsername()
expects either an array, or a string.
You can specify the search mode as a second parameter (Client::MODES['USERNAME']
OR Client::MODES['ID']
)
Example:
User/Mutes endpoints
Retrieve the users which you've muted
Example:
Mute user by username or ID
Example:
Unmute user by username or ID
Example:
Contributing
Fork/download the code and run
copy test/config/.env.example
to test/config/.env
and add your credentials for testing.
To run tests
To run code analyzer
All versions of twitter-api-v2-php with dependencies
ext-json Version *
php Version >=7.4
guzzlehttp/guzzle Version ^7.5.0
guzzlehttp/oauth-subscriber Version ^0.6.0