[英]Laravel notification won't send
I try to send notification to Twitter when new post created but I'm getting:我尝试在创建新帖子时向 Twitter 发送通知,但我收到:
Couldn't post Notification. Response: Bad Authentication data.
Notification class通知类
use NotificationChannels\Twitter\TwitterChannel;
use NotificationChannels\Twitter\TwitterStatusUpdate;
use App\Post;
class PostPublished extends Notification
{
use Queueable;
public function via($notifiable)
{
return [TwitterChannel::class, TelegramChannel::class];
}
public function toTwitter($post)
{
$title = $post->title;
$slug = $post->slug;
$image = $post->image;
return new TwitterStatusUpdate($title .' https://domain.co/blog/'. $slug, [$image]);
}
Post controller后控制器
use Illuminate\Notifications\Notifiable;
use App\Notifications\PostPublished;
$post->save();
$post->notify(new \App\Notifications\PostPublished($post));
Post model后模型
use Illuminate\Notifications\Notifiable;
use Notifiable;
It is definitely something wrong with your configuration or your tokens.您的配置或令牌肯定有问题。 It looks to me as if something is not set up properly.
在我看来,好像有些东西没有正确设置。 In your
config/services.php
file do you have the following?在您的
config/services.php
文件中,您是否有以下内容?
'twitter' => [
'consumer_key' => env('TWITTER_CONSUMER_KEY'),
'consumer_secret' => env('TWITTER_CONSUMER_SECRET'),
'access_token' => env('TWITTER_ACCESS_TOKEN'),
'access_secret' => env('TWITTER_ACCESS_SECRET')
]
Please check to ensure all of these are set correctly using tinker.请检查以确保所有这些都使用 tinker 正确设置。 In the terminal type
php artisan tinker
and then check each of the following one line at a time:在终端中输入
php artisan tinker
,然后一次检查以下每一行:
env('TWITTER_CONSUMER_KEY'),
env('TWITTER_CONSUMER_SECRET'),
env('TWITTER_ACCESS_TOKEN'),
env('TWITTER_ACCESS_SECRET')
All I needed to do was :我需要做的就是:
php artisan config:cach
composer dump-autoload
now it's working like charm.现在它就像魅力一样工作。
Note it can be type error in any part of .env file, not only twitter access tokens and key, for example:请注意,.env 文件的任何部分都可能是类型错误,不仅是 twitter 访问令牌和密钥,例如:
APP_NAME=Name of your App
instead of:代替:
APP_NAME="Name of your App"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.