twitter: Undefined property: stdClass::$media_id_string

Hi,

when i try to run my code i get

Undefined property: stdClass::$media_id_string

on

 $post->notify(new \App\Notifications\PostPublished($post));

here is my notification function:

public function toTwitter($post)
    {
        $title = $post->title;
        $slug = $post->slug;
        $image = $post->image;
        return (new TwitterStatusUpdate($title ."\n https://domain.co/blog/". $slug))->withImage('http://domain.co/storage/images/'.$image);
    }

any idea?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17

Most upvoted comments

@christophrumpel I solved the issue and just to let you know, all i had to do was

php artisan cach:clear
// then
composer dump-autoload

Also if someone else some day ends up here can double check their env values by tinker like:

php artisan tinker
// then
env('TWITTER_ACCESS_SECRET')
and so on...

If return the value that is set in env file they are good to go.

PS: Another thing maybe you like to mention in documents is that for image you must provide full address $post->image is not enough and returns error of can’t getting file, should be like http://domain.co/storage/images/$post->image

Have fun.

Thx a lot for mentioning it! I will add it to the docs. Glad it works now.

Have you checked the installation instructions here? https://github.com/laravel-notification-channels/twitter

You need to add these to the config/services.php file:

'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')
]

And you need to add those values to your .env file. Have you done that?