通过桌面应用程序的 API 报告 YouTube 视频

问题描述 投票:0回答:1

我目前正在开发一个桌面应用程序,需要能够使用 YouTube API 报告不当的 YouTube 视频。尽管我已经查看了 YouTube API 文档,但在理解如何实现以编程方式报告视频的过程方面遇到了挑战。我遇到过使用不同编程语言的示例代码,但我正在努力在 C# 中找到等效的解决方案。

我参考了 YouTube API 文档,特别是videos.reportAbuse 端点,它似乎提供了我需要的功能。但是,提供的代码示例是不同的编程语言,我无法在 C# 中找到类似的示例。

我非常感谢有关如何在 C# 中实现 reportAbuse 端点的任何帮助或指导,或者有关将示例代码从提供的文档转换为 C# 的任何指示。预先感谢您的帮助!

请不要投反对票。

string credentialsPath = "googlefile.json";

// Scopes for YouTube API
string[] scopes = { YouTubeService.Scope.YoutubeForceSsl };

// Load the credentials file
GoogleCredential credential;
using (var stream = new FileStream(credentialsPath, FileMode.Open, FileAccess.Read))
{
    credential = GoogleCredential.FromStream(stream).CreateScoped(scopes);
}

// Initialize the YouTube API service with OAuth2 credentials
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "My Project 55555"
});

// Video ID you want to report
string videoId = "xxxxx";

// Create the abuse report snippet
var abuseReport = new VideoAbuseReport();
abuseReport.VideoId = videoId;
abuseReport.ReasonId = "spam"; // You need to find the appropriate reason ID

// Submit the report
var reportRequest = youtubeService.Videos.ReportAbuse(abuseReport);
var response = reportRequest.Execute();

现在我正在使用 YouTubeService 并收到此错误“:'从 JSON 或 JSON 参数创建凭据时出错。无法识别的凭据类型。'”我已下载了 GoogleCredential json 文件。

c# youtube-api youtube-data-api desktop-application google-api-dotnet-client
1个回答
0
投票

这应该可以帮助您开始使用我为 YouTube 编写的授权代码。只需更改范围即可。

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

Console.WriteLine("Hello, World!");

const string pathToKeyFile = @"C:\Development\FreeLance\GoogleSamples\Credentials\credentials.json";

const string videoPath = "";

// scope of authorization needed from the user
var scopes = new[] { YouTubeService.Scope.Youtube };

// file to upload
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.FromFile(pathToKeyFile).Secrets,
    scopes,
    "test",
    CancellationToken.None).Result;

// Create the  Youtube service.
var service = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Daimto Youtube upload Quickstart"
});
© www.soinside.com 2019 - 2024. All rights reserved.