laravel-notification-channels / twitter

Twitter Notifications Channel for Laravel
http://laravel-notification-channels.com
MIT License
169 stars 44 forks source link

Intermittent ErrorException: Attempt to read property "media_id_string" #99

Closed topclaudy closed 1 year ago

topclaudy commented 1 year ago

ErrorException: Attempt to read property "media_id_string" on null in /var/www/stocktreats.com/vendor/laravel-notification-channels/twitter/src/TwitterChannel.php:82

This sometimes happens when posting tweet with image (just one image in my case)

christophrumpel commented 1 year ago

Can you please give a bit more details?

Are you already using v8?

topclaudy commented 1 year ago

Can you please give a bit more details?

Are you already using v8?

Yes! It happens on v8

christophrumpel commented 1 year ago

Ok thx. Any chance you can dump the Twitter call response? Should be this one: https://github.com/laravel-notification-channels/twitter/blob/master/src/TwitterChannel.php#L80

topclaudy commented 1 year ago

Given the error message, I think the call response is null in case of error. Do you want me to dump the response in case of success?

njoguamos commented 1 year ago

Experiencing the same error when I try to post a tweet that has an image.

Undefined property: stdClass::$media_id_string

Screenshot 2023-07-23 at 19 43 40
njoguamos commented 1 year ago

I dumped out the response from line 82. Here is the response.

Screenshot 2023-07-23 at 20 03 09
christophrumpel commented 1 year ago

Thanks. Can you confirm, that just sending a text tweet works?

njoguamos commented 1 year ago

I have managed to fix the issues by regenerating the credentials.

topclaudy commented 1 year ago

I also regenerated credentials before opening this issue, and the error persists (intermittently)

topclaudy commented 1 year ago

No problems with text-only tweets.

njoguamos commented 1 year ago

I dumped out the response from line 82. Here is the response.

Screenshot 2023-07-23 at 20 03 09

I suggest you start by debugging Twitter response.

topclaudy commented 1 year ago

I can't debug the error. This seems to work now without change in my code. As I said, it's intermittent in my situation and this start happening after upgrading to v8.

christophrumpel commented 1 year ago

Hey, with all the changes on Twitter API, it is often really difficult to debug issues because, aus you said, sometimes it just works again. For me it sounds like a problem with the app and credentials on the Twitter side, but if it keeps coming back, please post here again, and also the API response from Twitter so I can help debug. All the best 👍

topclaudy commented 1 year ago

Problem persists!! Text-only tweets work fine. Tweets with image(s) result in error. All attempts failed yesterday.

christophrumpel commented 1 year ago

Hey, sorry to hear that. Have you checked what the Twitter response is? This would help with debugging. (see messages above where to dump the Twitter response)

topclaudy commented 1 year ago

Here is the response: The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

I ran a job to post 2 notifications. The first one ALWAYS succeed. The second one results in this error. It looks like a problem when posting more than one tweets within 1 second.

topclaudy commented 1 year ago

Here is the response: The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

I ran a job to post 2 notifications. The first one ALWAYS succeed. The second one results in this error. It looks like a problem when posting more than one tweets within 1 second.

It keeps happening even when I pause for 15 seconds before the second tweet.

christophrumpel commented 1 year ago

Thanks for the update. I can take a look tomorrow.

christophrumpel commented 1 year ago

I tried it with the underlying Twitteroauth package and there I made it work to send a text and image.

@Nelwhix could you maybe take a look at this issue and see if you can tweet a text and image with this package?

Nelwhix commented 1 year ago

Okay

Nelwhix commented 1 year ago

I just tried posting three tweets consecutively with image and it succeeded. The error message The Twitter REST API v1 is no longer active. Please migrate to API v1.1. is strange because the package uses twitter API v1.1 for media upload. maybe if we could have more details of his setup so we know what could trigger the issue

christophrumpel commented 1 year ago

Thanks a lot @Nelwhix. 🙏 The issue might be connected to the app 🤔

@topclaudy have you tried to create a new Twitter app with new credentials? Could be an issue if the app already exists longer.

topclaudy commented 1 year ago

Hi @christophrumpel I created a new app and the error persists (same error: The Twitter REST API v1 is no longer active...). The new credentials from the new app work for Laravel Socialite tough. This is weird!

christophrumpel commented 1 year ago

This is really strange =/ I also ran into a few issues with Twitter where I do not why they do not work.

The app is also within a "project" on the Twitter developer page?

topclaudy commented 1 year ago

Yes! The app is within a project.

topclaudy commented 1 year ago

I noticed that the 2 consecutive tweets (with image) were posted successfully in the first attempt just after creating the new app/credentials. But the subsequent attempts failed.

christophrumpel commented 1 year ago

This sounds really weird. At this point I'm not sure how or if I can help.

What you could do is check out the package that we use under the hood: https://twitteroauth.com/ You could test if it works with this package, I use just that package in some projects too, because it is quite easy to use too.

topclaudy commented 1 year ago

@christophrumpel Thanks for the tips. It looks like a problem on Twitter... Oops! X. I'm gonna close this issue.

topclaudy commented 3 months ago

This was definitely an issue with the package. I updated to the last version and this issue is solved.