Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for Twitter V2 Timelines #1144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

josiasal
Copy link

@josiasal josiasal commented Nov 3, 2021

No description provided.

Copy link
Owner

@linvi linvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall.
One thing I noticed is that if you call the iterator twice, when the pagination_token is added there is an Exception happening for me.

I don't see how your code could be the reason of this but I noticed it.

eason : Unauthorized
Details : {"errors":[{"message":"Could not authenticate you","code":32}]}
 (0)
Code : 401
Date : 11/12/2021 00:31:00 +00:00
URL : https://api.twitter.com/2/users/1577389800/tweets?expansions=attachments.poll_ids%2Cattachments.media_keys%2Cauthor_id%2Centities.mentions.username%2Cgeo.place_id%2Cin_reply_to_user_id%2Creferenced_tweets.id%2Creferenced_tweets.id.author_id&media.fields=duration_ms%2Cheight%2Cmedia_key%2Cpreview_image_url%2Ctype%2Curl%2Cwidth&place.fields=contained_within%2Ccountry%2Ccountry_code%2Cfull_name%2Cgeo%2Cid%2Cname%2Cplace_type&poll.fields=duration_minutes%2Cend_datetime%2Cid%2Coptions%2Cvoting_status&tweet.fields=attachments%2Cauthor_id%2Ccontext_annotations%2Cconversation_id%2Ccreated_at%2Centities%2Cgeo%2Cid%2Cin_reply_to_user_id%2Clang%2Cpossibly_sensitive%2Creferenced_tweets%2Csource%2Ctext%2Cwithheld%2Cpublic_metrics&user.fields=created_at%2Cdescription%2Centities%2Cid%2Clocation%2Cname%2Cpinned_tweet_id%2Cprofile_image_url%2Cprotected%2Curl%2Cusername%2Cverified%2Cwithheld%2Cpublic_metrics&pagination_token=7140dibdnow9c7btw3q1g9zhsd4179i4fyr6n1ksgau5u
Twitter documentation description : Unauthorized -  Authentication credentials were missing or incorrect.

Do you happen to receive the same exception? Here is repro code:

var timelineIterator = client.TimelinesV2.GetUserTweetsTimelineIterator(new GetTimelinesV2Parameters("1577389800"));
var page1 = await timelineIterator.NextPageAsync();
// Error happens next line
var page2 = await timelineIterator.NextPageAsync();

I opened a request on twittercommunity: https://twittercommunity.com/t/401-on-timeline-request-with-pagination-token/162027

Comment on lines 29 to 35
// IBaseTweetsV2Parameters
query.AddParameterToQuery("expansions", parameters.Expansions);
query.AddParameterToQuery("media.fields", parameters.MediaFields);
query.AddParameterToQuery("place.fields", parameters.PlaceFields);
query.AddParameterToQuery("poll.fields", parameters.PollFields);
query.AddParameterToQuery("tweet.fields", parameters.TweetFields);
query.AddParameterToQuery("user.fields", parameters.UserFields);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with:

_tweetsV2QueryGenerator.AddTweetFieldsParameters(parameters, query);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

{
public class TimelinesV2QueryGenerator : ITimelinesV2QueryGenerator
{
public string GetTimelineQuery(IGetTimelinesV2Parameters parameters)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

        private readonly ITweetsV2QueryGenerator _tweetsV2QueryGenerator;

        public TimelinesV2QueryGenerator(ITweetsV2QueryGenerator tweetsV2QueryGenerator)
        {
            _tweetsV2QueryGenerator = tweetsV2QueryGenerator;
        }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.


namespace Tweetinvi.Client.V2
{
public interface ITimelinesV2Client
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include additional methods here to provide access directly to a single request and not necessarily the iterator.

This is similar to

Task<TimelinesV2Response> GetUserTweetsTimeline(string userId);
Task<TimelinesV2Response> GetUserTweetsTimeline(IGetTimelinesV2Parameters parameters);

// ...

Implementation example:

var iterator = GetUserTweetsTimelineIterator(parameters);
return (await iterator.NextPageAsync().ConfigureAwait(false)).ToArray();

I guess this can be done in another commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's work on this in the next commit.

Comment on lines 24 to 25
/// This object contains information about the number of users
/// returned in the current request and pagination details.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an error of description on the Twitter API website I think. Lets change this to

/// This object contains information about the Timeline Tweets
/// returned in the current request and pagination details.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@linvi linvi self-assigned this Nov 12, 2021
@linvi linvi added the feature label Nov 12, 2021
@linvi linvi added this to the Version 5.0 milestone Nov 12, 2021
@linvi
Copy link
Owner

linvi commented Nov 14, 2021

In a second commit, it will be good to add the documentation for Timelines.

@josiasal josiasal force-pushed the feature/add-support-for-timeline-v2 branch from 834ff6a to 0e50453 Compare November 15, 2021 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants