Download the PHP package abdulbaquee/twitter-oauth-v2 without Composer
On this page you can find all versions of the php package abdulbaquee/twitter-oauth-v2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdulbaquee/twitter-oauth-v2
More information about abdulbaquee/twitter-oauth-v2
Files in abdulbaquee/twitter-oauth-v2
Package twitter-oauth-v2
Short Description A modern PHP library for Twitter API v2 integration with OAuth 2.0 PKCE support
License MIT
Informations about the package twitter-oauth-v2
Twitter OAuth 2.0 PHP Library
A modern, robust PHP library for integrating Twitter API v2 using OAuth 2.0 with PKCE support. This library is framework-agnostic and works seamlessly with core PHP.
Features
- OAuth 2.0 Authorization with PKCE support
- Token management (access tokens, refresh tokens)
- User management
- Tweet creation and management
- List management
- Tweet interactions (like, retweet, reply)
- User interactions (follow, block, mute)
- PSR standards compliance (PSR-4, PSR-7, PSR-18)
- Framework-agnostic session handling
Note: Media uploads (images, GIFs, videos) are not yet supported in Twitter API v2. This feature will be added once Twitter releases the media upload endpoints for v2.
Requirements
- PHP 7.4 or higher
- Composer
- Twitter API credentials (Client ID and Client Secret)
Installation
Configuration
-
Copy the example configuration file:
- Edit
config.php
and fill in your Twitter API credentials:
Session Handling
The library provides a flexible session handling system that works with any PHP framework. Choose the appropriate session handler for your framework:
Vanilla PHP
Laravel
Symfony
Custom Implementation
You can create your own session handler by implementing the SessionHandlerInterface
:
PHP Configuration Requirements (Optimal)
For optimal performance and security, we recommend the following PHP settings:
Note: These are recommended settings. Adjust them according to your specific environment and security requirements.
Usage
Basic Setup
User Operations
Tweet Operations
List Operations
User Interactions
Example Pages
The library includes several example pages to demonstrate its functionality:
auth.php
- OAuth 2.0 authorization flowcallback.php
- OAuth callback handlingusers.php
- User profile and relationship operationstweet.php
- Tweet creation and managementlists.php
- List creation and managementinteractions.php
- Tweet interactions (like, retweet, reply)basic_usage.php
- Basic usage examples
Error Handling
The library throws exceptions for various error conditions:
RuntimeException
for general errorsGuzzleException
for HTTP request failures
Base Example Class
The library provides a BaseExample
class that serves as a foundation for implementing Twitter API operations. This class handles common functionality like authentication and request handling.
Features
- HTTP Method Support: Built-in methods for GET, POST, and DELETE requests
- Authentication: Automatic token management and refresh
- Error Handling: Comprehensive error handling
- Common Operations: Pre-built methods for common Twitter API operations
Usage Example
Extending the Base Class
You can extend the BaseExample
class to add custom functionality:
Error Handling
The base class includes comprehensive error handling:
- API errors are properly formatted
- Network errors are caught and handled
- JSON parsing errors are handled gracefully
Media Upload
The media upload functionality supports:
- Image files (JPG, PNG, GIF)
- Video files (MP4)
- Proper MIME type handling
- Automatic file size validation
Note: Media upload functionality is subject to Twitter API v2 limitations and requirements.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This library is licensed under the MIT License.
All versions of twitter-oauth-v2 with dependencies
ext-json Version *
guzzlehttp/guzzle Version ^7.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.0 || ^2.0
psr/log Version ^1.1
psr/cache Version ^1.0 || ^2.0 || ^3.0