{"id":13729477,"url":"https://github.com/noweh/twitter-api-v2-php","last_synced_at":"2025-05-15T21:05:42.588Z","repository":{"id":38200325,"uuid":"408480723","full_name":"noweh/twitter-api-v2-php","owner":"noweh","description":"PHP package providing easy and fast access to Twitter API V2.","archived":false,"fork":false,"pushed_at":"2025-05-06T14:44:18.000Z","size":138,"stargazers_count":122,"open_issues_count":4,"forks_count":36,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T15:53:09.866Z","etag":null,"topics":["api","php","twitter","twitter-api","twitter-api-v2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noweh.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-20T14:41:58.000Z","updated_at":"2025-05-06T14:42:17.000Z","dependencies_parsed_at":"2024-01-06T13:08:43.567Z","dependency_job_id":"a80d8208-ea96-4aae-9067-fab293e66d1d","html_url":"https://github.com/noweh/twitter-api-v2-php","commit_stats":{"total_commits":51,"total_committers":5,"mean_commits":10.2,"dds":0.07843137254901966,"last_synced_commit":"1fc1049985daeebcc6a547d9c8ca10c644413e00"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noweh%2Ftwitter-api-v2-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noweh%2Ftwitter-api-v2-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noweh%2Ftwitter-api-v2-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noweh%2Ftwitter-api-v2-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noweh","download_url":"https://codeload.github.com/noweh/twitter-api-v2-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254422755,"owners_count":22068678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","php","twitter","twitter-api","twitter-api-v2"],"created_at":"2024-08-03T02:01:00.937Z","updated_at":"2025-05-15T21:05:42.560Z","avatar_url":"https://github.com/noweh.png","language":"PHP","readme":"# Twitter API V2 for PHP\r\n\r\n![PHP](https://img.shields.io/badge/PHP-v7.4+-828cb7.svg?style=flat-square\u0026logo=php)\r\n[![Badge Twitter](https://img.shields.io/badge/Twitter%20API-v2-828cb7.svg?style=flat-square\u0026logo=twitter\u0026color=1DA1F2)](https://developer.twitter.com/en/docs/twitter-api)\r\n[![Run Tests](https://github.com/noweh/twitter-api-v2-php/actions/workflows/run-tests.yml/badge.svg)](https://github.com/noweh/twitter-api-v2-php/actions/workflows/run-tests.yml)\r\n[![MIT Licensed](https://img.shields.io/github/license/noweh/twitter-api-v2-php)](licence.md)\r\n[![last version](https://img.shields.io/packagist/v/noweh/twitter-api-v2-php)](https://packagist.org/packages/noweh/twitter-api-v2-php)\r\n[![Downloads](https://img.shields.io/packagist/dt/noweh/twitter-api-v2-php)](https://packagist.org/packages/noweh/twitter-api-v2-php)\r\n[![twitter](https://img.shields.io/twitter/follow/NowehJS?style=social)](https://x.com/NowehJS)\r\n\r\nTwitter API V2 is a PHP package which provides an easy and fast access to Twitter REST API for Version 2 endpoints.\r\n\r\n## Documentation\r\n\r\n* [Installation](#installation)\r\n* [Github Actions](#github-actions)\r\n* [Usage](#usage)\r\n    - [Active your developer account](#active-your-developer-account)\r\n    - [Configuration setup](#configuration-setup)\r\n    - [API Functionality](#api-functionality)\r\n      - [Include the HTTP headers provided by Twitter in the response](#include-the-http-headers-provided-by-twitter-in-the-response)\r\n* [Tweets endpoints](#tweet-endpoints)\r\n    - [Timeline endpoints](#timeline-endpoints)\r\n        - [Find Recent Mentioning for a User](#find-recent-mentioning-for-a-user)\r\n        - [Find Recent Tweets for a User](#find-recent-tweets-for-a-user)\r\n        - [Reverse Chronological Timeline by user ID](#reverse-chronological-timeline-by-user-id)\r\n    - [Tweet/Likes endpoints](#tweetlikes-endpoints)\r\n        - [Tweets liked by a user](#tweets-liked-by-a-user)\r\n        - [Users who liked a tweet](#users-who-liked-a-tweet)\r\n    - [Tweet/Lookup endpoints](#tweetlikes-endpoints)\r\n        - [Search specific tweets](#search-specific-tweets)\r\n        - [Find all replies from a Tweet](#find-all-replies-from-a-tweet)\r\n    - [Tweet endpoints](#tweetlikes-endpoints)\r\n        - [Fetch a tweet by Id](#fetch-a-tweet-by-id)\r\n        - [Create a new Tweet](#create-a-new-tweet)\r\n        - [Upload image to Twitter (and use in Tweets)](#upload-image-to-twitter-and-use-in-tweets)\r\n    - [Tweet/Quotes endpoints](#tweetquotes-endpoints)\r\n        - [Returns Quote Tweets for a Tweet specified by the requested Tweet ID](#returns-quote-tweets-for-a-tweet-specified-by-the-requested-tweet-id)\r\n    - [Retweet endpoints](#retweet-endpoints)\r\n        - [Retweet a Tweet](#retweet-a-tweet)\r\n    - [Tweet/Replies endpoints](#tweetreplies-endpoints)\r\n        - [Hide a reply to a Tweet](#hide-a-reply-to-a-tweet)\r\n        - [Unhide a reply to a Tweet](#unhide-a-reply-to-a-tweet)\r\n    - [Tweet/Bookmarks endpoints](#tweetbookmarks-endpoints)\r\n        - [Lookup a user's Bookmarks](#lookup-a-users-bookmarks)\r\n* [Users endpoints](#users-endpoints)\r\n    - [User/Blocks endpoints](#userblocks-endpoints)\r\n        - [Retrieve the users which you've blocked](#retrieve-the-users-which-youve-blocked)\r\n    - [User/Follows endpoints](#userfollows-endpoints)\r\n        - [Retrieve the users which are following you](#retrieve-the-users-which-are-following-you)\r\n        - [Retrieve the users which you are following](#retrieve-the-users-which-you-are-following)\r\n        - [Follow a user](#follow-a-user)\r\n        - [Unfollow a user](#unfollow-a-user)\r\n    - [User/Lookup endpoints](#userlookup-endpoints)\r\n        - [Find me](#find-me) \r\n        - [Find Twitter Users](#find-twitter-users)\r\n    - [User/Mutes endpoints](#usermutes-endpoints)\r\n        - [Retrieve the users which you've muted](#retrieve-the-users-which-youve-muted)\r\n        - [Mute user by username or ID](#mute-user-by-username-or-id)\r\n        - [Unmute user by username or ID](#unmute-user-by-username-or-id)\r\n* [Contributing](#contributing)\r\n    - [To run test](#to-run-tests)\r\n    - [To run code analyzer](#to-run-code-analyzer)\r\n\r\n## Installation\r\nTo begin, you'll need to add the component to your `composer.json`\r\n```shell\r\ncomposer require noweh/twitter-api-v2-php\r\n```\r\nAfter adding the component, update your packages using `composer update` or install them using `composer install`.\r\n\r\n## Github Actions\r\n\r\nThis repository uses [Github Actions](https://github.com/noweh/twitter-api-v2-php/actions) for each push/pull request, employing [PHPStan/PHPUnit](/.github/workflows/run-tests.yml).\r\n\r\nConsequently, with each valid push, a new Tweet is posted from the [Twitter test account](https://twitter.com/canWeDeploy/status/1538477133487644672).\r\n\r\n## Usage\r\n\r\n### Active your developer account\r\nBefore anything else, you must follow [this tutorial](https://developer.twitter.com/en/docs/tutorials/getting-started-with-r-and-v2-of-the-twitter-api).\r\n- [Request approval for a developer account](https://developer.twitter.com/en/apply-for-access);\r\n- Once your developer account is approved, you will need to [create a Project](https://developer.twitter.com/en/docs/projects/overview);\r\n- Enable read/write access for your Twitter app;\r\n- Generate Consumer Keys and Authentication Tokens;\r\n- Retrieve your Keys and Tokens from the Twitter Developer portal.\r\n\r\n### Configuration setup\r\nExpected settings are as follows:\r\n```php\r\nuse Noweh\\TwitterApi\\Client;\r\n\r\n$settings = [\r\n    'account_id' =\u003e 'YOUR_ACCOUNT_ID',\r\n    'access_token' =\u003e 'YOUR_ACCESS_TOKEN',\r\n    'access_token_secret' =\u003e 'YOUR_TOKEN_SECRET',\r\n    'consumer_key' =\u003e 'YOUR_CONSUMER_KEY',\r\n    'consumer_secret' =\u003e 'YOUR_CONSUMER_SECRET',\r\n    'bearer_token' =\u003e 'YOUR_BEARER_TOKEN',\r\n    'free_mode' =\u003e false, // Optional\r\n    'api_base_uri' =\u003e 'https://api.twitter.com/2/', // Optional\r\n]; \r\n\r\n$client = new Client($settings);\r\n```\r\n\r\nBy 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.\r\n\r\nFor a quick mock server setup you can use [mockoon](https://mockoon.com/).\r\n\r\n### API Functionality\r\nAll API calls are triggered when the `performRequest()` method is invoked.\r\nDepending 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).\r\n\r\n#### Include the HTTP headers provided by Twitter in the response\r\nThe `performRequest()` method accepts a second parameter, `$withHeaders`, which is a boolean value.\r\nSetting this parameter to `true` will include the headers information in the response.\r\n\r\nHere are some examples of information included in headers:\r\n- `x-rate-limit-limit`: the rate limit ceiling for that given endpoint\r\n- `x-rate-limit-remaining`: the number of requests left for the 15-minute window\r\n- `x-rate-limit-reset`: the remaining window before the rate limit resets, in UTC epoch seconds\r\n\r\nExample:\r\n```php\r\n$response = $this-\u003eclient-\u003etweet()-\u003ecreate()\r\n    -\u003eperformRequest([\r\n        'text' =\u003e 'Test Tweet... '\r\n    ],\r\n    withHeaders: true)\r\n;\r\n\r\n/*\r\nOutput:\r\nobject(stdClass)#399 (2) {\r\n    [\"data\"]=\u003e\r\n    object(stdClass)#398 (3) {\r\n        [\"edit_history_tweet_ids\"]=\u003e\r\n        array(1) {\r\n            [0]=\u003e\r\n            string(19) \"1690304934837637121\"\r\n        }\r\n        [\"id\"]=\u003e\r\n        string(19) \"1690304934837637121\"\r\n        [\"text\"]=\u003e\r\n        string(39) \"Test Tweet...\"\r\n    }\r\n    [\"headers\"]=\u003e\r\n        ...\r\n        [\"x-rate-limit-limit\"]=\u003e\r\n        array(1) {\r\n            [0]=\u003e\r\n            string(5) \"40000\"\r\n        }\r\n        [\"x-rate-limit-reset\"]=\u003e\r\n        array(1) {\r\n            [0]=\u003e\r\n            string(10) \"1691835953\"\r\n        }\r\n        [\"x-rate-limit-remaining\"]=\u003e\r\n        array(1) {\r\n            [0]=\u003e\r\n            string(5) \"39998\"\r\n        }\r\n        ...\r\n    }\r\n}\r\n*/\r\n```\r\n### Free mode\r\n\r\nThis API can be used in free mode, which allows for a limited usage of the API.\r\nIn this mode, the [Find me](#find-me) method is the only one that can be used.\r\nYou have to set the `free_mode` parameter to `true` when creating the client.\r\n\r\nExample:\r\n```php\r\n...\r\n$settings['free_mode'] = true;\r\n$client = new Client($settings);\r\n```\r\n\r\n---\r\n## Tweets endpoints\r\n\r\n## Timeline endpoints\r\n\r\n### Find Recent Mentioning for a User\r\nExample:\r\n```php\r\n$return = $client-\u003etimeline()-\u003egetRecentMentions($accountId)-\u003eperformRequest();\r\n```\r\n\r\n### Find Recent Tweets for a User\r\nExample:\r\n```php\r\n$return = $client-\u003etimeline()-\u003egetRecentTweets($accountId)-\u003eperformRequest();\r\n```\r\n\r\n### Reverse Chronological Timeline by user ID\r\nExample:\r\n```php\r\n$return = $client-\u003etimeline()-\u003egetReverseChronological()-\u003eperformRequest();\r\n```\r\n\r\n## Tweet/Likes endpoints\r\n\r\n### Tweets liked by a user\r\nExample:\r\n```php\r\n$return = $client-\u003etweetLikes()-\u003eaddMaxResults($pageSize)-\u003egetLikedTweets($accountId)-\u003eperformRequest();\r\n```\r\n\r\n### Users who liked a tweet\r\nExample:\r\n```php\r\n$return = $client-\u003etweetLikes()-\u003eaddMaxResults($pageSize)-\u003egetUsersWhoLiked($tweetId)-\u003eperformRequest();\r\n```\r\n\r\n## Tweet/Lookup endpoints\r\n\r\n### Search specific tweets\r\nExample:\r\n```php\r\n$return = $client-\u003etweetLookup()\r\n    -\u003eshowMetrics()\r\n    -\u003eonlyWithMedias()\r\n    -\u003eaddFilterOnUsernamesFrom([\r\n        'twitterdev',\r\n        'Noweh95'\r\n    ], \\Noweh\\TwitterApi\\TweetLookup::OPERATORS['OR'])\r\n    -\u003eaddFilterOnKeywordOrPhrase([\r\n        'Dune',\r\n        'DenisVilleneuve'\r\n    ], \\Noweh\\TwitterApi\\TweetLookup::OPERATORS['AND'])\r\n    -\u003eaddFilterOnLocales(['fr', 'en'])\r\n    -\u003eshowUserDetails()\r\n    -\u003eperformRequest()\r\n;\r\n\r\n$client-\u003etweetLookup()\r\n    -\u003eaddMaxResults($pageSize)\r\n    -\u003eaddFilterOnKeywordOrPhrase($keywordFilter)\r\n    -\u003eaddFilterOnLocales($localeFilter)\r\n    -\u003eshowUserDetails()\r\n    -\u003eshowMetrics()\r\n    -\u003eperformRequest()\r\n;\r\n```\r\n\r\n### Find all replies from a Tweet\r\n```php\r\n-\u003eaddFilterOnConversationId($tweetId);\r\n```\r\n\r\n## Tweet endpoints\r\n\r\n### Fetch a tweet by Id\r\nExample:\r\n```php\r\n$return = $client-\u003etweet()-\u003e-\u003efetch(1622477565565739010)-\u003eperformRequest();\r\n```\r\n\r\n### Create a new Tweet\r\nExample:\r\n```php\r\n$return = $client-\u003etweet()-\u003ecreate()-\u003eperformRequest(['text' =\u003e 'Test Tweet... ']);\r\n```\r\n\r\n### Upload image to Twitter (and use in Tweets)\r\nExample:\r\n```php\r\n$file_data = base64_encode(file_get_contents($file));\r\n$media_info = $client-\u003euploadMedia()-\u003eupload($file_data);\r\n$return = $client-\u003etweet()-\u003ecreate()\r\n    -\u003eperformRequest([\r\n        'text' =\u003e 'Test Tweet... ', \r\n        \"media\" =\u003e [\r\n            \"media_ids\" =\u003e [\r\n                (string)$media_info[\"media_id\"]\r\n            ]\r\n        ]\r\n    ])\r\n;\r\n```\r\n\r\n## Tweet/Quotes endpoints\r\n\r\n### Returns Quote Tweets for a Tweet specified by the requested Tweet ID\r\nExample:\r\n```php\r\n$return = $client-\u003etweetQuotes()-\u003egetQuoteTweets($tweetId)-\u003eperformRequest();\r\n```\r\n\r\n## Retweet endpoints\r\n\r\n### Retweet a Tweet\r\nExample:\r\n```php\r\n$return = $client-\u003eretweet()-\u003eperformRequest(['tweet_id' =\u003e $tweet_id]);\r\n```\r\n\r\n## Tweet/Replies endpoints\r\n\r\n### Hide a reply to a Tweet\r\nExample:\r\n```php\r\n$return = $client-\u003e-\u003etweetReplies()-\u003ehideReply($tweetId)-\u003eperformRequest(['hidden' =\u003e true]);\r\n```\r\n\r\n### Unhide a reply to a Tweet\r\nExample:\r\n```php\r\n$return = $client-\u003e-\u003etweetReplies()-\u003ehideReply($tweetId)-\u003eperformRequest(['hidden' =\u003e false]);\r\n```\r\n\r\n## Tweet/Bookmarks endpoints\r\n\r\n### Lookup a user's Bookmarks\r\nExample:\r\n```php\r\n$return = $client-\u003etweetBookmarks()-\u003elookup()-\u003eperformRequest();\r\n```\r\n\r\n---\r\n\r\n## Users endpoints\r\n\r\n## User/Blocks endpoints\r\n\r\n### Retrieve the users which you've blocked\r\nExample:\r\n```php\r\n$return = $client-\u003euserBlocks()-\u003elookup()-\u003eperformRequest();\r\n```\r\n\r\n## User/Follows endpoints\r\n\r\n### Retrieve the users which are following you\r\nExample:\r\n```php\r\n$return = $client-\u003euserFollows()-\u003egetFollowers()-\u003eperformRequest();\r\n```\r\n\r\n### Retrieve the users which you are following\r\nExample:\r\n```php\r\n$return = $client-\u003euserFollows()-\u003egetFollowing()-\u003eperformRequest();\r\n```\r\n\r\n### Follow a user\r\nExample:\r\n```php\r\n$return = $client-\u003euserFollows()-\u003efollow()-\u003eperformRequest(['target_user_id' =\u003e $userId]);\r\n```\r\n\r\n### Unfollow a user\r\nExample:\r\n```php\r\n$return = $client-\u003euserFollows()-\u003eunfollow($userId)-\u003eperformRequest(['target_user_id' =\u003e self::$userId]);\r\n```\r\n\r\n## User/Lookup endpoints\r\n\r\n### Find Me\r\nExample:\r\n```php\r\n$return = $client-\u003euserMeLookup()-\u003eperformRequest();\r\n```\r\n\r\n### Find Twitter Users\r\n`findByIdOrUsername()` expects either an array, or a string.\r\n\r\nYou can specify the search mode as a second parameter (`Client::MODES['USERNAME']` OR `Client::MODES['ID']`)\r\n\r\nExample:\r\n```php\r\n$return = $client-\u003euserLookup()\r\n    -\u003efindByIdOrUsername('twitterdev', \\Noweh\\TwitterApi\\UserLookup::MODES['USERNAME'])\r\n    -\u003eperformRequest()\r\n;\r\n```\r\n\r\n## User/Mutes endpoints\r\n\r\n### Retrieve the users which you've muted\r\nExample:\r\n```php\r\n$return = $client-\u003euserMutes()-\u003elookup()-\u003eperformRequest();\r\n```\r\n\r\n### Mute user by username or ID\r\nExample:\r\n```php\r\n$return = $client-\u003euserMutes()-\u003emute()-\u003eperformRequest(['target_user_id' =\u003e $userId]);\r\n```\r\n\r\n### Unmute user by username or ID\r\nExample:\r\n```php\r\n$return = $client-\u003euserMutes()-\u003eunmute()-\u003eperformRequest(['target_user_id' =\u003e $userId]);\r\n```\r\n\r\n---\r\n\r\n## Contributing\r\nFork/download the code and run\r\n```shell\r\ncomposer install\r\n```\r\n\r\ncopy `test/config/.env.example` to `test/config/.env` and add your credentials for testing.\r\n\r\n### To run tests\r\n```shell\r\n./vendor/bin/phpunit\r\n```\r\n\r\n### To run code analyzer\r\n```shell\r\n./vendor/bin/phpstan analyse .\r\n```\r\n","funding_links":[],"categories":["Libraries"],"sub_categories":["PHP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoweh%2Ftwitter-api-v2-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoweh%2Ftwitter-api-v2-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoweh%2Ftwitter-api-v2-php/lists"}