j7mbo/twitter-api-php
最新稳定版本:1.0.6
Composer 安装命令:
composer require j7mbo/twitter-api-php
包简介
Simple PHP Wrapper for Twitter API v1.1 calls
README 文档
README
Simple PHP Wrapper for Twitter API v1.1 calls
Instructions in StackOverflow post here with examples. This post shows you how to get your tokens and more. If you found it useful, please upvote / leave a comment! :)
The aim of this class is simple. You need to:
- Include the class in your PHP code
- Create a twitter app on the twitter developer site
- Enable read/write access for your twitter app
- Grab your access tokens from the twitter developer site
- Choose a twitter API URL to make the request to
- Choose either GET / POST (depending on the request)
- Choose the fields you want to send with the request (example:
array('screen_name' => 'usernameToBlock'))
You really can't get much simpler than that. The above bullet points are an example of how to use the class for a POST request to block a user, and at the bottom is an example of a GET request.
Installation
Normally: If you don't use composer, don't worry - just include TwitterAPIExchange.php in your application.
require_once('TwitterAPIExchange.php');
Via Composer:
composer require j7mbo/twitter-api-php
How To Use
Set access tokens
$settings = array( 'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN", 'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET", 'consumer_key' => "YOUR_CONSUMER_KEY", 'consumer_secret' => "YOUR_CONSUMER_SECRET" );
Choose URL and Request Method
$url = 'https://api.twitter.com/1.1/blocks/create.json'; $requestMethod = 'POST';
Choose POST fields (or PUT fields if you're using PUT)
$postfields = array( 'screen_name' => 'usernameToBlock', 'skip_status' => '1' );
Perform the request!
$twitter = new TwitterAPIExchange($settings); echo $twitter->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest();
GET Request Example
Set the GET field BEFORE calling buildOauth(); and everything else is the same:
$url = 'https://api.twitter.com/1.1/followers/ids.json'; $getfield = '?screen_name=J7mbo'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); echo $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest();
That is it! Really simple, works great with the 1.1 API. Thanks to @lackovic10 and @rivers on SO!
j7mbo/twitter-api-php 适用场景与选型建议
j7mbo/twitter-api-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.59M 次下载、GitHub Stars 达 1.82k, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「twitter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 j7mbo/twitter-api-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 j7mbo/twitter-api-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 j7mbo/twitter-api-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Handles basic OAuth/OAuth2 authentication along with classes for common services
Simple Twitter API wrapper
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
A PSR-7 compatible library for making CRUD API endpoints
A helper module for pdf-print, print and social share functionality based on bootstrap to custom modules.
Laravel package for the simplification and integration of many of your users most wanted login providers. Installation is a breeze. Never worry about OAuth again.
统计信息
- 总下载量: 9.59M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1823
- 点击次数: 25
- 依赖项目数: 43
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2026-01-04