linvi / tweetinvi

Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
MIT License
1.01k stars 220 forks source link

403 Forbidden on Filtered Stream v1.1 #1209

Open Scobiform opened 1 year ago

Scobiform commented 1 year ago

Hi there,

I am getting 403 Forbidden since 2 days on v1.1. Anyone else having issues?

Exception... Reason : \n\n\nError 403 Code : -1</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/orrishu"><img src="https://avatars.githubusercontent.com/u/39120842?v=4" />orrishu</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>+1</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/Marilyth"><img src="https://avatars.githubusercontent.com/u/19623152?v=4" />Marilyth</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>It seems v1.1 streams are now deprecated. So you will have to migrate to v2. <a href="https://twittercommunity.com/t/announcing-the-deprecation-of-v1-1-statuses-filter-endpoint/182960">https://twittercommunity.com/t/announcing-the-deprecation-of-v1-1-statuses-filter-endpoint/182960</a></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/Scobiform"><img src="https://avatars.githubusercontent.com/u/9046630?v=4" />Scobiform</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <blockquote> <p>It seems v1.1 streams are now deprecated. So you will have to migrate to v2. <a href="https://twittercommunity.com/t/announcing-the-deprecation-of-v1-1-statuses-filter-endpoint/182960">https://twittercommunity.com/t/announcing-the-deprecation-of-v1-1-statuses-filter-endpoint/182960</a></p> </blockquote> <p>Oh damn. Thanks for the hint. </p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/lgjluis"><img src="https://avatars.githubusercontent.com/u/22641055?v=4" />lgjluis</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <p>In v2 only works Sample Stream. Do you have an example of Filtered Stream?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/keytrap-x86"><img src="https://avatars.githubusercontent.com/u/17864005?v=4" />keytrap-x86</a> commented <strong> 1 year ago</strong> </div> <div class="markdown-body"> <blockquote> <p>In v2 only works Sample Stream. Do you have an example of Filtered Stream?</p> </blockquote> <p>Filteread streams will stop today (29th of April) :</p> <p><a href="https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api">https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api</a></p> <p>But anyways here you go</p> <pre><code class="language-csharp">public void StartFilteredStream(ITwitterBot bot, CancellationToken token) { _logger.LogDebug("Starting filtered stream"); // Create the twitter filtered stream FilteredStream = bot.AuthenticatedUser.Client.Streams.CreateFilteredStream( new CreateFilteredTweetStreamParameters { TweetMode = TweetMode.Extended }); // Set the mention targets (users which will set of the OnMention event) FilteredStream.AddTrack($"@{bot.Config.Name}"); // Only look for the users in the mentions FilteredStream.MatchOn = MatchOn.UserMentionEntities; // Set the event that occurs on a mention FilteredStream.MatchingTweetReceived += async (sender, args) => { var mentionedTweet = args.Tweet; if (mentionedTweet != null) { // For some reason, I need to do this to get the full tweet var (Tweet, Error) = await bot.GetTweet(mentionedTweet.Id); if (Tweet != null) OnMention?.Invoke(bot, Tweet); else if (string.IsNullOrEmpty(Error) == false) _logger.LogWarning("Error getting tweet {id} : {err}", mentionedTweet.Id, Error); } }; // Set these events just for info FilteredStream.DisconnectMessageReceived += (sender, args) => { _logger.LogWarning("Stream DisconnectMessageReceived code: {code} reason: {reason} stream name: {name}", args.DisconnectMessage?.Code, args.DisconnectMessage?.Reason, args.DisconnectMessage?.StreamName); }; _ = Task.Run(async () => { var streamFails = 0; // Start the stream and wait for it to end // If the stream ends prematurely, we let it having a break for 30 seconds. // If it fails 3 times, end the stream do { try { await FilteredStream.StartMatchingAllConditionsAsync(); } catch (TaskCanceledException) { // Ignored } catch (TwitterException e) { _logger.LogError("Twitter exception while starting filtered stream: {err}", e.Message); } catch (Exception ex) { _logger.LogError("Error while starting filtered stream: {err}", ex.Message); } streamFails++; await Task.Delay(30_000); } while (streamFails < 3); // Send a message with the telegram bot to inform that the stream has ended await _telegramBot.SendMessage("⛔ The stream has ended. We'll try to restart the app..."); // Try to restart the app _logger.LogDebug("Restarting app..."); Process.Start(new ProcessStartInfo("/usr/sbin/service", "saveflix restart") { Verb = "sudo" }); }, token); }</code></pre> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>