laravel-notification-channels / facebook-poster
使用通知在Facebook上创建帖子
6.1.0
2024-03-12 05:35 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.2
- illuminate/notifications: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- mockery/mockery: ^1.3.3
- phpunit/phpunit: ^10.5.0
README
此包使得使用Laravel通知通道在Facebook上发布帖子变得容易。
内容
安装
您可以通过Composer安装此包。
composer require laravel-notification-channels/facebook-poster
配置
您需要获取Facebook页面ID以及具有“pages_read_engagement”和“pages_manage_post”权限的页面访问令牌。您需要通过App Review才能使用这些权限。然后,将配置添加到您的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)。请参阅许可证文件以获取更多信息。