utxo-one/twitter-ultimate-php
Composer 安装命令:
composer require utxo-one/twitter-ultimate-php
包简介
The Ultimate PHP Wrapper for the Twitter v2 API
README 文档
README
A complete and opinionated API Wrapper implementation for the Twitter v2 API. Full docblocks for all methods and strict return types make it easy for developers by providing all the method names and parameters to your IDE.
Prerequisites
- => PHP 8.1
- Composer
- Twitter Developer Account
Installation
composer require utxo-one/twitter-ultimate-php
Usage
Tweet Client
The tweet client can be initialized either to get public information, or to perform authenticated actions.
Public API Calls
You only need to provide your bearerToken to initialize a tweet client that accesses public information.
use UtxoOne\TwitterUltimatePhp\Clients\TweetClient; $client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $tweet = $client->getTweet('1272846378268347');
Authenticated API Calls
To make an authenticated API call, you need to provide your apiToken , apiSecret, accessToken, accessSecret.
Access tokens are generated after the user authenticates your app.
use UtxoOne\TwitterUltimatePhp\Clients\TweetClient; $client = new TweetClient( apiKey: $_ENV['TWITTER_API_KEY'], apiSecret: $_ENV['TWITTER_API_SECRET'], accessToken: $_ENV['TWITTER_ACCESS_TOKEN'], accessSecret: $_ENV['TWITTER_ACCESS_SECRET'], ); $tweet = $client->tweet('Hello World!');
Available Tweet Client Methods:
getTweet()getTweets()getQuoteTweets()getLikingUsers()getRetweetedByUsers()tweet()deleteTweet()likeTweet()unlikeTweet()retweet()unrtweet()bookmarkTweet()unbookmarkTweet()
Get Tweet Details
use UtxoOne\TwitterUltimatePhp\Clients\TweetClient; $client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $tweet = $client->getTweet('1565628118001455105'); // Available Getter Methods. $tweet->getId(); $tweet->getText(); $tweet->getCreatedAt(); $tweet->getAuthorId(); $tweet->getConversationId(); $tweet->getInReplyToUserId(); $tweet->getLang(); $tweet->getSource(); $tweet->isWithheld(); $tweet->getPublicMetricS(); $tweet->getReplySettings(); $tweet->getReferencedTweets(); $tweet->getEntities(); $tweet->getGeo(); $tweet->getContextAnnotations(); $tweet->isPossiblySensitive(); $tweet->getAttachements();
Get Multiple Tweet Details
use UtxoOne\TwitterUltimatePhp\Clients\TweetClient; $client = new TweetClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $tweets = $client->getTweets(['1565628118001455105', '1565999511536914433'])->all(); foreach($tweets as $tweet) { $tweet->getId(); // ... }
User Management Methods
Getting a User's Details
use UtxoOne\TwitterUltimatePhp\Clients\UserClient; $client = new UserClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $user = $client->getUserByUsername('utxoone'); $user->getId(); $user->getName(); $user->getUsername(); $user->getCreatedAt(); $user->getDescription(); $user->getLocation(); $user->getPinnedTweetId(); $user->getProfileImageUrl(); $user->getUrl(); $user->isVerified(); $user->isProtected(); $user->getEntities();
Getting a User's Liked Tweets
use UtxoOne\TwitterUltimatePhp\Clients\UserClient; $client = new UserClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $user = $client->getUserByUsername('utxoone'); $likedTweets = $client->getLikedTweets($user->getId())->all(); foreach ($likedTweets as $likedTweet) { $likedTweet->getId(); $likedTweet->getText(); // ... }
Follow a User
use UtxoOne\TwitterUltimatePhp\Clients\UserClient; $client = new UserClient( apiKey: $_ENV['TWITTER_API_KEY'], apiSecret: $_ENV['TWITTER_API_SECRET'], accessToken: $_ENV['TWITTER_ACCESS_TOKEN'], accessSecret: $_ENV['TWITTER_ACCESS_SECRET'], ); $user = $client->getUserByUsername('utxo_one'); $tweet = $client->follow($user->getId());
Available Methods
getUserByUsername()getUserById()getLikedTweets()getFollowers()getFollowing()follow()unfollow()getBlocks()block()unblock()mute()unmute()
List Management Methods
Getting a List's Details
use UtxoOne\TwitterUltimatePhp\Clients\ListClient; $client = new ListClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $list = $client->getList('64651656516516516'); $list->getId(); $list->getFollowerCount(); $list->getCreatedAt(); $list->getMemberCount(); $list->isPrivate(); $list->getDescription(); $list->getOwnerId();
Create a List
use UtxoOne\TwitterUltimatePhp\Clients\ListClient; $client = new ListClient( apiKey: $_ENV['TWITTER_API_KEY'], apiSecret: $_ENV['TWITTER_API_SECRET'], accessToken: $_ENV['TWITTER_ACCESS_TOKEN'], accessSecret: $_ENV['TWITTER_ACCESS_SECRET'], ); $list = $client->createList( name: 'My New List', description: 'My New List Description', private: false, ); $list->getId();
Available Methods
getList()getUserOwnedLists()getListTweets()getListMembers()getUserMemberships()getListFollowers()getUserFollowedLists()getUserPinnedLists()createList()updateList()deleteList()addListMember()removeListMember()followList()unfollowList()pinList()unpinList()
Space Management Methods
Getting a Space's Details
use UtxoOne\TwitterUltimatePhp\Clients\SpaceClient; $client = new SpaceClient(bearerToken: $_ENV['TWITTER_BEARER_TOKEN']); $space = $client->getSpace('64651656516516516'); $space->getId(); $space->getTitle(); $space->getCreatedAt(); $space->getUpdatedAt(); $space->getHostIds(); $space->getState(); $space->isTicketed(); $space->getLand(); $space->getCreatorId();
utxo-one/twitter-ultimate-php 适用场景与选型建议
utxo-one/twitter-ultimate-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.02k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2022 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 utxo-one/twitter-ultimate-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 utxo-one/twitter-ultimate-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 5.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 21
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-03