gpt4 book ai didi

c# - Google.Apis.Requests.RequestError 权限不足 [403]

转载 作者:行者123 更新时间:2023-11-30 14:50:48 27 4
gpt4 key购买 nike

我遇到以下错误,我想获得发布在 YouTube 视频上的所有评论。

所以基本上我正在传递视频 ID,我想获得与该视频相关的所有评论

Google.Apis.Requests.RequestError
Insufficient Permission [403]

Errors [Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]]

这是我的代码:

protected void btnGetVideoDesc_Click(object sender, EventArgs e)
{
string videoId = txtVideoID.Text;
YoutubeVideo video = new YoutubeVideo(videoId);
lblTitle.Text = video.title;
lblPublishedDate.Text = video.publishdate.ToShortDateString();
}

public class YoutubeVideo
{
public string id, title, description ;
public DateTime publishdate;

public YoutubeVideo(string id)
{
this.id = id;
YoutubeAPI.GetVideoInfo(this);
}
}

public class YoutubeAPI
{
private static YouTubeService ytService = Auth();

private static YouTubeService Auth()
{
UserCredential creds;
var service = new YouTubeService();
try
{
using (var stream = new FileStream(@"C:\v-mmarat\Project\EMEA_Development\YoutubeWebCrawling\YoutubeWebCrawling\youtube_client_secret.json", FileMode.Open, FileAccess.Read))
{
creds = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.YoutubeReadonly }, "user", CancellationToken.None,
new FileDataStore("YoutubeAPI")
).Result;
}
service = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = creds,
ApplicationName = "YoutubeAPI",
ApiKey = "My_API_Key"

});
}
catch (Exception e)
{ }
return service;
}

public static void GetVideoInfo(YoutubeVideo video)
{
try
{
//This code work perfectly
var videoRequest = ytService.Videos.List("snippet");

videoRequest.Id = video.id;

var response = videoRequest.Execute();
if (response.Items.Count > 0)
{
video.title = response.Items[0].Snippet.Title;
video.description = response.Items[0].Snippet.Description;
video.publishdate = response.Items[0].Snippet.PublishedAt.Value;
}




else
{
//error
}

var CommentRequest = ytService.Comments.List("snippet");

videoRequest.Id = video.id;

//Getting error at this line after CommentRequest.Execute();
var Commentresponse = CommentRequest.Execute();
if (Commentresponse.Items.Count > 0)
{
video.title = Commentresponse.Items[0].Snippet.ChannelId;
video.description = Commentresponse.Items[0].Snippet.TextDisplay;
video.publishdate = Commentresponse.Items[0].Snippet.PublishedAt.Value;
}
else
{
//error
}
}
catch (Exception e)
{ }
}

最佳答案

GoogleWebAuthorizationBroker.AuthorizeAsync 中,将“user”更改为“admin”。

关于c# - Google.Apis.Requests.RequestError 权限不足 [403],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35880845/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com