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 219 forks source link

V2 Filtered Search Rate Limit #1095

Open layinka opened 3 years ago

layinka commented 3 years ago

I am trying to use the v2 filtered search to monitor an handle, but i am getting "Rate Limit Exceeded" almost immediately the stream starts. Here is my code. What am i doing wrong?

           var stream = client.StreamsV2.CreateFilteredStream();

            stream.TweetReceived += Stream_TweetReceived;
            var pars = new StartFilteredStreamV2Parameters();
            pars.ClearCustomQueryParameters();
            pars.ClearAllFields();
            pars.Expansions = new HashSet<string>(new string[] { "in_reply_to_user_id", "author_id","referenced_tweets.id","referenced_tweets.id.author_id" });
            pars.UserFields = new HashSet<string>(new string[] { "created_at", "entities", "id", "name", "username", "in_reply_to_user_id", "profile_image_url" });
            pars.TweetFields= new HashSet<string>(new string[] { "author_id","conversation_id", "created_at","in_reply_to_user_id","referenced_tweets","text" });
            pars.CustomQueryParameters.Add(new Tuple<string, string>( "@", "permabot"));

            try
            {
                await stream.StartAsync(pars);
            }catch(Exception ee)
            {
                Debug.WriteLine(ee.Message);
            }
linvi commented 3 years ago

I know this is a very late response. Though if you managed to find an answer for it, I would be happy to learn what was your solution so that I can help others in the future.

layinka commented 3 years ago

Hi, Never found a solution. I had to implement this in nodejs eventually

if you find a solution,let me know too

linvi commented 3 years ago

So the same api (v2) worked for you in node but never worked with Tweetinvi?

layinka commented 3 years ago

Yes

weirdyang commented 2 years ago

Hi, where can I find the documentation for streamv2, sample and filtered?

I can only find the filteredstream docs for v1; https://linvi.github.io/tweetinvi/dist/streams-v1.1/filtered-stream.html

         _stream = Client.StreamsV2.CreateFilteredStream();
            var pars = new StartFilteredStreamV2Parameters();
            pars.AddCustomQueryParameter("text", "(happy OR happiness) -birthday -is:retweet");
            _stream.TweetReceived += HandleTweet;
            _stream.EventReceived += HandleEvent;

            await _stream.StartAsync(pars);
 TweetStream.Services.TweetListener[0]
      {"errors":[{"parameters":{"text":["(happy OR happiness) -birthday -is:retweet"]},"message":"The query parameter [text] is not one of [backfill_minutes,expansions,tweet.fields,media.fields,poll.fields,place.fields,user.fields]"}],"title":"Invalid Request","detail":"One or more parameters to your request was invalid.","type":"https://api.twitter.com/2/problems/invalid-request"}

The twitter api for v2 also looks different; https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/quick-start

It now uses rules

Adding and removing rules
You will be using the [POST /2/tweets/search/stream/rules](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules) endpoint when both adding and deleting rules from your stream.

To add one or more rule to your stream, submit an add JSON body with an array that contains the value parameter including the rule, and the optional tag parameter including free-form text that you can use to [identify which returned Tweets match this rule](https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/matching-returned-tweets).

nvm, found it!

thanks for the library.

SamuelJames101 commented 2 years ago

@weirdyang Can you send a link for the docs, I can't find them and am confused how to use streamV2

tomazi776 commented 2 years ago

@weirdyang Yep, It would be helpful if you could share what you've found so that others who are trying to use this library without extensive documentation on the V2 can use it.

And also, @linvi why there is almost no documentation on your website/github on the V2 filtered streams? Are you planning on adding it ever? (Thanks for all the hard work though, it's greatly appreciated!)

weirdyang commented 2 years ago

Hi @tomazi776 and @SamuelJames101

I based my code off of this comment: https://github.com/linvi/tweetinvi/issues/1070#issuecomment-704780561

I have uploaded my incomplete but working implementation here: https://github.com/weirdyang/tweet-stream/blob/main/tweet-stream-lib/Configuration/TweetConfiguration.cs

rules in appsettings should be in this format:

  "Rule": [
    {
      "Tag": "cats with images",
      "Value": "cat has:images -is:retweet"
    }

and app credentials:

  "AppCredentials": {
    "ConsumerKey": "<Your consumer key>",
    "ConsumerSecret": "<Your consumer secret>",
    "BearerToken": "<Your bearer token>"
  }