Php Laravel通知赢得';不发送

Php Laravel通知赢得';不发送,php,laravel,Php,Laravel,我尝试在创建新帖子时向Twitter发送通知,但我得到: Couldn't post Notification. Response: Bad Authentication data. 代码 通知类 use NotificationChannels\Twitter\TwitterChannel; use NotificationChannels\Twitter\TwitterStatusUpdate; use App\Post; class PostPublished extends Noti

我尝试在创建新帖子时向Twitter发送通知,但我得到:

Couldn't post Notification. Response: Bad Authentication data.
代码 通知类

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]);
    }
岗位控制员

use Illuminate\Notifications\Notifiable;
use App\Notifications\PostPublished;

$post->save();
$post->notify(new \App\Notifications\PostPublished($post));
后期模型

use Illuminate\Notifications\Notifiable;

use Notifiable;
问题:
  • 为什么我会犯这个错误
  • 如何修复它

  • 您的配置或令牌肯定有问题。在我看来,好像有些东西设置不正确。在
    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')
    ]
    
    请检查以确保使用tinker正确设置所有这些。在终端类型
    php artisan tinker
    中,然后一次检查以下每一行:

    env('TWITTER_CONSUMER_KEY'),
    env('TWITTER_CONSUMER_SECRET'),
    env('TWITTER_ACCESS_TOKEN'),
    env('TWITTER_ACCESS_SECRET')
    
    解决了的 我所需要做的就是:

    php artisan config:cach
    composer dump-autoload
    

    现在它工作得很有魅力

    注意,.env文件的任何部分都可能出现类型错误,而不仅仅是twitter访问令牌和密钥,例如:

    APP_NAME=Name of your App
    
    而不是:

    APP_NAME="Name of your App"
    

    .env
    文件中的API键是wrong@Ohgodwhy刚才我创建了一个新的应用程序,这就是我在
    env
    文件中使用它们的方式谢谢你的回答,我的服务和env文件中确实有这些。但我也会顺便再检查一下,让你知道好吧,我和tinker检查过了,这是我得到的:|现在它工作了:)我所需要的就是清除配置缓存并转储我的作曲家数据,谢谢你,我能帮上忙!