Skip to content

CorvinRyder/TwitterTimelineParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TwitterTimelineParser

Description

A .NET library that fetch the user's Like timeline, Home timeline (For you) and Latest home timeline (Following) from Twitter's graphql API, and convert them to a bunch of Tweet objects that contain the contet, attached image and video, post date and such. The screenshot below is the example of an returned object. image

The usage of this library? You can have a look at the sample folder, it contains 2 possible use cases of the library:

  1. Download every media you "liked" on Twitter, or;
  2. Forward every "liked" tweet to a Telegram channel.

Just be creative and you should be able to make it a even better use :)

Please note that this library use Regex to parse the content of the returned JSON. It provides a bit better performance than parsing it as a whole JSON object. However, a sightly bit change to the JSON format may make the library unusable.

I planned to rewrite it with some JSON library in the future.

Table of Contents

Installation

Just add the source code of the library, and use the library as one of the reference of your project should do the job. Or just refer the built .DLL file in your project.

Usage

  1. Refer the library in your project by following the Installation section.
  2. Create a TwitterLikeParser object, remember to supply the necessary values to the constructor:
    1. timelineType - The timeline you want to fetch. It's a TimelineType enum value.
    2. twitterId - The twitter ID (the number) of someone, not to confuse with the handle of a Twitter user
    3. cookie - The cookie on the Twitter website. You should be able to get it by using F12 Devtool of any browser. It's how this library doesn't require user to login
    4. csrt - The CSRT token of the user, you can also get it by using F12 Devtool of any browser.
    5. resultCount - The maximum number of result you want the API to return once.
  3. Call NextPage() to start getting the first page of the timeline. If the values supplied to the constructor are correct, it should return an array of Tweet object.
  4. Keep calling NextPage() to get the second page and so on, until it return false, indicating that no more page is available.

A simple example call would be:

TwitterLikeParser likeList = new TwitterLikeParser(TimelineType.LikeTimeline, twitter_id, cookie, csrt, 20);
while (parser.NextPage())
{
    foreach (Tweet tweet in parser.Tweets)
    {
        // Have fun with the Tweet object
    }
}

Tweet and Media objects

The Tweet and Media objects contains the following fields:

public class Tweet
{
    public String Author { get; set; }
    public String TweetId { get; set; }
    public String Content { get; set; }
    public String CreateDate { get; set; }
    public String TweetUrl { get; set; }
    public Media[] Medias { get; set; }
    public String MediaJoined { get; set; }
}

public class Media
{
    // "photo" and "video"
    public String MediaType { get; set; }
    public String Url { get; set; }
}

License

License

About

A .NET framework library that download the user's timeline and convert it to .NET objects

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages