stdray.Twitter 1.2.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package stdray.Twitter --version 1.2.2
                    
NuGet\Install-Package stdray.Twitter -Version 1.2.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="stdray.Twitter" Version="1.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="stdray.Twitter" Version="1.2.2" />
                    
Directory.Packages.props
<PackageReference Include="stdray.Twitter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add stdray.Twitter --version 1.2.2
                    
#r "nuget: stdray.Twitter, 1.2.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package stdray.Twitter@1.2.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=stdray.Twitter&version=1.2.2
                    
Install as a Cake Addin
#tool nuget:?package=stdray.Twitter&version=1.2.2
                    
Install as a Cake Tool

stdray.Twitter

A C# library for retrieving Twitter/X.com tweet content by ID.

Description

stdray.Twitter provides a simple API for retrieving tweet data, including text and media files (images and videos). The library uses an authentication mechanism similar to yt-dlp to work with Twitter/X GraphQL API.

Features

  • Retrieve tweet data by ID
  • Extract tweet text
  • Extract media files (images, videos, animated GIFs)
  • For videos: get all variants with bitrate and resolution information
  • Automatic resolution extraction from URL if not specified in JSON

Usage

using stdray.Twitter;
using System.Linq;

var client = new TwitterClient(new HttpClient());
var tweet = await client.GetTweetById("1989071142053900550");

var photos = tweet.Media.OfType<PhotoMedia>().ToArray();
var videos = tweet.Media.OfType<VideoMedia>().ToArray();

Console.WriteLine($"Text: {tweet.Text}");
Console.WriteLine($"Photos: {photos.Length}");
Console.WriteLine($"Videos/GIFs: {videos.Length}");

foreach (PhotoMedia photo in photos)
{
    Console.WriteLine($"Image: {photo.Url}");
}

foreach (VideoMedia video in videos)
{
    var bestVariant = video.Variants
        .OrderByDescending(v => v.Bitrate ?? 0)
        .First();

    var kind = video.Type == MediaType.AnimatedGif ? "GIF" : "Video";
    Console.WriteLine($"{kind}: {bestVariant.Url} ({bestVariant.Width}x{bestVariant.Height})");
}

Source

This library is based on the authentication mechanism and Twitter API logic from the yt-dlp project.

Source code reference:

Requirements

  • .NET 8.0

Building

This project uses Cake build automation system with GitVersion for semantic versioning. You can build the project in several ways:

Using Cake (Cross-platform)

  1. Prerequisites: Install .NET SDK 8.0 or later

  2. Run the build:

    # On Windows
    .\build.ps1
    
    # On macOS/Linux
    chmod +x build.sh
    ./build.sh
    

Using .NET CLI directly

# Restore packages
dotnet restore

# Build the solution
dotnet build -c Release

# Run tests
dotnet test -c Release

# Pack the NuGet package
dotnet pack -c Release

Note for AI agents: When running commands in PowerShell (pwsh), avoid using && as a separator (e.g., cd D:/prj/github/stdray/stdray-twitter && git status -sb). Use ; if you need to chain commands in pwsh.

Build Targets

The Cake build script supports the following targets:

  • Default: Cleans, restores, builds and runs tests
  • Build: Builds the solution
  • Test: Runs unit tests
  • Pack: Creates NuGet packages
  • Publish: Publishes NuGet packages to nuget.org
  • CI: Full CI pipeline (build, test, pack, publish)

Example: .\build.ps1 -Target="Pack" -Configuration="Release"

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

  • Pull requests trigger build and test validation
  • Commits to the main branch trigger the full CI/CD pipeline including NuGet package publishing

License

See LICENSE file (if applicable).

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.3-ci.1 43 3/3/2026
1.2.2 477 12/10/2025
1.1.2-ci.12 422 12/10/2025
1.1.2-ci.11 396 12/9/2025
1.1.2-ci.10 91 11/29/2025
1.1.2-ci.9 68 11/29/2025
1.1.2-ci.8 89 11/29/2025
1.1.2-ci.7 68 11/29/2025
1.0.0 122 11/29/2025