Natsukage.PixivCS 0.1.3

dotnet add package Natsukage.PixivCS --version 0.1.3
                    
NuGet\Install-Package Natsukage.PixivCS -Version 0.1.3
                    
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="Natsukage.PixivCS" Version="0.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Natsukage.PixivCS" Version="0.1.3" />
                    
Directory.Packages.props
<PackageReference Include="Natsukage.PixivCS" />
                    
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 Natsukage.PixivCS --version 0.1.3
                    
#r "nuget: Natsukage.PixivCS, 0.1.3"
                    
#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 Natsukage.PixivCS@0.1.3
                    
#: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=Natsukage.PixivCS&version=0.1.3
                    
Install as a Cake Addin
#tool nuget:?package=Natsukage.PixivCS&version=0.1.3
                    
Install as a Cake Tool

PixivCS

NuGet Version NuGet Downloads .NET Version License

PixivCS 是一个现代化的 C# 版本 Pixiv API 库,基于 .NET 8.0 平台开发。

致谢: 本项目是 pixivpy 的 C# 实现,接口设计与数据结构均基于原项目。感谢 upbit 及其贡献者们为开源社区提供的卓越工作。

安装

通过 NuGet 安装:

dotnet add package Natsukage.PixivCS

快速开始

using PixivCS.Api;
using PixivCS.Network;

// 创建 API 实例
var api = new PixivAppApi();

// 认证
var authResult = await api.AuthAsync("your_refresh_token");

// 获取插画详情
var illustDetail = await api.GetIllustDetailAsync("133368512");
Console.WriteLine($"标题: {illustDetail.Illust?.Title}");

// 搜索插画
var searchResult = await api.SearchIllustAsync("初音ミク");
foreach (var illust in searchResult.Illusts ?? [])
{
    Console.WriteLine($"ID: {illust.Id}, 标题: {illust.Title}");
}

获取 Refresh Token

由于密码登录已不再支持,请使用 refresh_token 进行认证。获取 refresh_token 的方法:

连接方式

支持三种连接方式:

普通连接

var config = new ConnectionConfig { Mode = ConnectionMode.Normal };
var api = new PixivAppApi(config);

免代理直连

var config = new ConnectionConfig { Mode = ConnectionMode.DirectBypass };
var api = new PixivAppApi(config);

注意: 在大陆网络环境下,直连 Pixiv 的 IP 地址速度通常较慢。特别是在进行图片下载时,原图下载可能需要很长时间,请设置足够长的超时时间。如果您有优质代理服务,建议优先使用代理方式连接。

代理连接

var config = new ConnectionConfig 
{ 
    Mode = ConnectionMode.Proxy,
    ProxyUrl = "http://127.0.0.1:7890"
};
var api = new PixivAppApi(config);

示例程序

查看 PixivCS.Tests 项目获取完整的使用示例,该项目可以直接编译运行。

文档

详细文档请参考项目 Wiki

许可证

MIT

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.

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
0.1.3 165 8/13/2025
0.1.2 233 8/5/2025
0.1.1 172 8/4/2025
0.1.0 141 8/4/2025

v0.1.3 - Breaking change: Separated SearchTarget enum into SearchTarget (for illust) and NovelSearchTarget (for novel) to correctly support different search targets. Novel search now supports 'text' and 'keyword' targets while illust search supports 'title_and_caption' target.