Weibo.Apis.Interfaces
1.0.2
dotnet add package Weibo.Apis.Interfaces --version 1.0.2
NuGet\Install-Package Weibo.Apis.Interfaces -Version 1.0.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="Weibo.Apis.Interfaces" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Weibo.Apis.Interfaces" Version="1.0.2" />
<PackageReference Include="Weibo.Apis.Interfaces" />
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 Weibo.Apis.Interfaces --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Weibo.Apis.Interfaces, 1.0.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 Weibo.Apis.Interfaces@1.0.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=Weibo.Apis.Interfaces&version=1.0.2
#tool nuget:?package=Weibo.Apis.Interfaces&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Weibo.Apis.Interfaces
微博无状态发布 API 接口定义库,提供微博图片上传、视频上传和内容发布相关的接口定义和数据传输对象(DTO)。
功能特性
- 🚀 图片上传:支持本地文件上传和URL文件上传两种方式
- 🎬 视频上传:支持视频上传并自动生成截图封面
- 📝 微博发布:支持纯文本、图片、视频的微博发布
- 👤 用户信息:自动从Cookie提取用户信息
- ✅ 数据验证:内置完整的数据验证特性
- 📋 完整文档:提供详细的XML文档注释和使用示例
支持的接口
用户信息接口
GetUserInfo- 从Cookie中自动提取用户信息(UID、昵称、粉丝数等)
图片上传接口
UploadImage- 本地图片文件上传UploadImageFromUrl- 通过URL上传图片
视频上传接口
UploadVideo- 本地视频文件上传(自动生成截图)UploadVideoFromUrl- 通过URL上传视频
微博发布接口
PublishWeibo- 发布微博(支持纯文本、图片、视频)
安装
dotnet add package Weibo.Apis.Interfaces
使用示例
获取用户信息
var userInfo = await weiboService.GetUserInfo(new GetUserInfoInput
{
Cookie = "XSRF-TOKEN=xxx; SCF=xxx; SUB=xxx; ...",
Proxy = "http://127.0.0.1:7890" // 可选
});
Console.WriteLine($"用户ID: {userInfo.Uid}");
Console.WriteLine($"昵称: {userInfo.Nick}");
Console.WriteLine($"粉丝数: {userInfo.FollowersCount}");
上传图片
// 方式1: 文件流上传
var imageResult = await weiboService.UploadImage(new UploadImageInput
{
File = imageFile,
Cookie = cookie
});
// 方式2: URL上传
var imageResult = await weiboService.UploadImageFromUrl(new UploadImageFromUrlInput
{
FileUrl = "https://example.com/image.jpg",
Cookie = cookie
});
Console.WriteLine($"图片ID: {imageResult.Pid}");
上传视频
// 方式1: 文件流上传
var videoResult = await weiboService.UploadVideo(new UploadVideoInput
{
File = videoFile,
Cookie = cookie,
Title = "我喜欢的动漫"
});
// 方式2: URL上传
var videoResult = await weiboService.UploadVideoFromUrl(new UploadVideoFromUrlInput
{
FileUrl = "https://example.com/video.mp4",
Cookie = cookie,
Title = "精彩视频"
});
Console.WriteLine($"视频ID: {videoResult.MediaId}");
Console.WriteLine($"封面ID: {videoResult.CoverPid}");
Console.WriteLine($"截图数量: {videoResult.Screenshots.Count}");
发布微博
// 发布纯文本微博
var result = await weiboService.PublishWeibo(new PublishWeiboInput
{
Content = "今天天气真好!#微博#",
Cookie = cookie,
Visible = 0 // 0=公开,1=仅自己可见
});
// 发布图片微博
var result = await weiboService.PublishWeibo(new PublishWeiboInput
{
Content = "美丽的风景 #旅行#",
Cookie = cookie,
PicIds = new List<WeiboMediaItem>
{
new WeiboMediaItem { Type = "image/jpeg", Pid = "0093aHS1gy1i9rj88r71uj31b90qlapo" }
}
});
// 发布视频微博
var result = await weiboService.PublishWeibo(new PublishWeiboInput
{
Content = "精彩视频 #视频分享#",
Cookie = cookie,
MediaId = videoResult.MediaId,
CoverPid = videoResult.CoverPid,
MediaGroupId = videoResult.MediaGroupId,
Visible = 0
});
Console.WriteLine($"微博ID: {result.MblogId}");
Console.WriteLine($"发布时间: {result.CreatedAt}");
完整发布流程
// 1. 上传视频
var uploadResult = await weiboService.UploadVideo(new UploadVideoInput
{
File = videoFile,
Cookie = cookie,
Title = "我喜欢的动漫"
});
// 2. 发布微博
var publishResult = await weiboService.PublishWeibo(new PublishWeiboInput
{
Content = "大家觉得好看吗?#动漫# #视频分享#",
Cookie = cookie,
MediaId = uploadResult.MediaId,
CoverPid = uploadResult.CoverPid,
MediaGroupId = uploadResult.MediaGroupId,
Visible = 0 // 公开发布
});
Console.WriteLine($"发布成功!微博ID: {publishResult.MblogId}");
数据验证
所有DTO类都包含完整的数据验证特性:
[Required]- 必填字段验证[MaxLength]- 最大长度验证- 自动参数验证和错误提示
版本要求
- .NET 6.0 / 8.0 / 9.0 / 10.0
- Microsoft.AspNetCore.Http.Features 5.0.17+
注意事项
- Cookie 获取: 需要从浏览器中获取完整的微博 Cookie,必须包含
XSRF-TOKEN,SCF,SUB,SUBP,ALF等字段 - Cookie 有效期: Cookie 会过期,需要定期更新
- 代理设置: 如果需要使用代理,支持 HTTP 和 SOCKS5 代理
- 文件大小限制: 视频文件建议不超过 1GB
- 上传超时: 视频上传可能需要较长时间,已设置 50 分钟超时
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
更新日志
v1.0.0
- 初始版本发布
- 支持用户信息获取
- 支持图片上传(本地文件和URL文件)
- 支持视频上传(本地文件和URL文件,自动生成截图)
- 支持微博发布(纯文本、图片、视频)
- 完整的数据验证支持
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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 is compatible. 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.
-
net10.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
-
net6.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
-
net8.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
-
net9.0
- Microsoft.AspNetCore.Http.Features (>= 5.0.17)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.0:
- 初始版本发布