tatter/reddit
Composer 安装命令:
composer require tatter/reddit
包简介
Reddit SDK for CodeIgniter 4
README 文档
README
Reddit SDK for CodeIgniter 4
Quick Start
- Install with Composer:
> composer require tatter/reddit - Supply Reddit credentials in .env
- Get API results:
foreach (service('reddit')->fetch('new') as $thing)
{
echo (string) $thing; // "Comment" or "Link"
echo $thing->link_permalink; // E.g. "https://www.reddit.com/r/pythonforengineers/comments/jox9zy/great_video_for_the_python_programers"
}
Description
Reddit SDK provides a framework-ready wrapper to the API endpoints describe in the Reddit API documentation.
Configuration (optional)
The library's default behavior can be altered by extending its config file. Copy examples/Reddit.php to app/Config/ and follow the instructions in the comments. If no config file is found in app/Config then the library will use its own.
Credentials
This library requires a valid Reddit application to acquire access tokens that work with API. For more details read the Reddit OAuth2 wiki.
- Login to Reddit and visit the "authorized applications" page (https://www.reddit.com/prefs/apps/)
- Under "developed applications" select "create an app..."
- Select "script" as the application type
- Provide a name, description, and URLs in the required text fields
- Select "create app"
Once your application is created you will need to copy the "client ID" and "secret" (see the wiki article above for help). Add these along with your username and password into your project's .env file, for example:
#--------------------------------------------------------------------
# REDDIT API
#--------------------------------------------------------------------
reddit.clientId = as98-asdn3h93r
reddit.clientSecret = LKhsa-ASJDn9a8sdion_laskdn0
reddit.username = MyFiRsTrEdItTbOt
reddit.password = ReallySecurePassword321
Usage
The easiest way to access the client is via the CodeIgniter's Services:
$reddit = service('reddit');
The client will handle authentication (assuming your credentials are valid), rate limiting,
response filtering and formatting. Access client methods in chains to set up the request,
then use fetch() to kick it off:
$comments = $reddit->subreddit('catgifs')->limit(10)->fetch('comments');
For more advanced needs you may use the request($uri, $data, $query) method which returns
the actual Response object, providing access to headers, etc. See also
HTTP/RedditRequest.php and HTTP/RedditResponse.php for some of the API handling
done "under the hood".
Troubleshooting
Should something go wrong all anticipated exceptions are wrapped in Tatter\Reddit\Exceptions\RedditException,
so you can catch them and figure out what happened:
try
{
$comments = $reddit->subreddit('php')->fetch('new');
}
catch (\Tatter\Reddit\Exceptions\RedditException $e)
{
echo $e->getMessage(); // "API responded with an error: Invalid authorization"
}
tatter/reddit 适用场景与选型建议
tatter/reddit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 937 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「codeigniter」 「sdk」 「reddit」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tatter/reddit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tatter/reddit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tatter/reddit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Library to validate and parse social media profile URLs
The CodeIgniter Redis package
Laravel Reddit API wrapper
Addon to enable social login providers for the Miniframe PHP Framework.
Reddit JSON API offers an easy way to retrieve data from subreddits in no time.
统计信息
- 总下载量: 937
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-21