isaacongoma / facebook-poster
使用通知在Facebook上创建帖子
5.0.0
2021-01-09 09:44 UTC
Requires
- php: ^7.3|^8.0
- guzzlehttp/guzzle: ^7.2
- illuminate/notifications: ^8.0
- illuminate/support: ^8.0
Requires (Dev)
- mockery/mockery: ^1.3.3
- phpunit/phpunit: ~9.0
README
此包使您可以使用Laravel通知通道轻松地在Facebook上发布帖子。
内容
安装
您可以通过Composer安装此包。
composer require laravel-notification-channels/facebook-poster
配置
您需要获取Facebook页面ID以及具有“pages_read_engagement”和“pages_manage_post”权限的页面访问令牌。您将需要通过应用审核才能使用这些权限。然后,将配置添加到您的config/services.php
文件中。
... 'facebook_poster' => [ 'page_id' => env('FACEBOOK_PAGE_ID'), 'access_token' => env('FACEBOOK_ACCESS_TOKEN'), ],
用法
按照Laravel的文档添加通道到您的通知类。
发布Facebook帖子
use NotificationChannels\FacebookPoster\FacebookPosterChannel; use NotificationChannels\FacebookPoster\FacebookPosterPost; class NewsWasPublished extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return [FacebookPosterChannel::class]; } /** * Get the Facebook post representation of the notification. * * @param mixed $notifiable. * @return \NotificationChannels\FacebookPoster\FacebookPosterPost */ public function toFacebookPoster($notifiable) { return new FacebookPosterPost('Laravel notifications are awesome!'); } }
发布带链接的Facebook帖子
您还可以在帖子中发布链接。您只需将URL传递给withLink
方法。
public function toFacebookPoster($notifiable) { return (new FacebookPosterPost('Laravel notifications are awesome!')) ->withLink('https://laravel.net.cn'); }
使用自定义配置发布Facebook帖子
您可以在您的通知类中实现routeNotificationForFacebookPoster()
,以提供自定义配置。
public function routeNotificationForFacebookPoster(): array { return [ 'page_id' => 'customPageId', 'access_token' => 'customAccessToken', ]; }
变更日志
请参阅变更日志以了解最近更改了哪些内容。
测试
$ composer test
贡献
请参阅贡献指南以获取详细信息。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。