codewizz/laravel-reddit-api

Laravel Reddit API 包装器

0.3.0 2021-03-15 18:24 UTC

This package is not auto-updated.

Last update: 2024-09-20 06:49:51 UTC


README

Latest Version on Packagist Total Downloads

使用此包,您可以轻松地从 Reddit API 获取数据。

Laravel 对 https://github.com/rotorcowboy/Phapper 的包装

支持 Laravel 5.x - 8.x。

以下是一些提供的方法示例

use RedditAPI;

//fetch top Reddit posts
RedditAPI::getTop();

//fetch top picture posts of Margot Robbie, limit to 100
RedditAPI::search('Margot Robbie ', null, 'top', null, 'pics', 100);

安装

此包可以通过 Composer 安装。

composer require codewizz/laravel-reddit-api

如果您使用的是 Laravel 5.5+,服务提供者和别名将自动注册。您可以继续到 "发布配置"。

手动注册服务

您必须安装此服务提供者。

// config/app.php
'providers' => [
    ...
    CodeWizz\RedditAPI\RedditAPIServiceProvider::class,
    ...
];

此包还附带了一个门面,它提供了一种调用类的方法。

// config/app.php
'aliases' => [
    ...
    'RedditAPI' => CodeWizz\RedditAPI\RedditAPIFacade::class,
    ...
];

发布配置

您应该使用以下命令发布此包的配置文件

php artisan vendor:publish --provider="CodeWizz\RedditAPI\RedditAPIServiceProvider"

以下配置文件将发布在 config/reddit-api.php

return [
    'endpoint_standard' => 'https://www.reddit.com',
    'endpoint_oauth' => 'https://oauth.reddit.com',
    
    'username' => env('REDDIT_USERNAME', ''),
    'password' => env('REDDIT_PASSWORD', ''),
    'app_id' => env('REDDIT_APP_ID', ''),
    'app_secret' => env('REDDIT_APP_SECRET', ''),
    
    'response_format' => 'STD', // STD | ARRAY
    
    'scopes' => 'save,modposts,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,read,report,submit,subscribe,vote,wikiedit,wikiread'
];

关于 CodeWizz

CodeWizz 是一家位于立陶宛的 Web 开发代理机构。您可以在我们的网站上找到更多信息 在这里

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件