Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# YouTube API服务帐户返回';禁止403';插入播放列表项时_C#_.net_Api_Youtube_Youtube Api - Fatal编程技术网

C# YouTube API服务帐户返回';禁止403';插入播放列表项时

C# YouTube API服务帐户返回';禁止403';插入播放列表项时,c#,.net,api,youtube,youtube-api,C#,.net,Api,Youtube,Youtube Api,我正在编写一个简单的应用程序,它从订阅的频道获取一些新的上传,并将它们添加到指定的播放列表中。服务帐户类型与以下代码一起使用: var certificate = new X509Certificate2(certificateFileName, "notasecret", X509KeyStorageFlags.Exportable); var serviceInitializer = new ServiceAccountCredential.Initializer(serviceAccoun

我正在编写一个简单的应用程序,它从订阅的频道获取一些新的上传,并将它们添加到指定的播放列表中。服务帐户类型与以下代码一起使用:

var certificate = new X509Certificate2(certificateFileName, "notasecret", X509KeyStorageFlags.Exportable);
var serviceInitializer = new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
        Scopes = new[] { YouTubeService.Scope.Youtube }
};
var serviceInitializerInstance = serviceInitializer.FromCertificate(certificate);

var credential = new ServiceAccountCredential(serviceInitializerInstance);
var youtubeService = new YouTubeService(new BaseClientService.Initializer
{
        HttpClientInitializer = credential,
        ApplicationName = applicationName
});
我已成功读取所有必要信息,但当我尝试将项目插入播放列表时,它总是返回以下错误:

错误:禁止访问Google.api.Requests.RequestError。请求 可能未经适当授权。[403]

错误[ 消息[禁止访问。请求可能未正确授权。]位置[-]原因[禁止]域[yo utube.common]]

这似乎是一些核心API的一般错误根据链接

我看过很多样品,它们都是一样的。我的代码是:

var newPlaylistItemClone = new PlaylistItem();
newPlaylistItem.Snippet = new PlaylistItemSnippet();
newPlaylistItem.Snippet.PlaylistId = playlist.Id;
newPlaylistItem.Snippet.ResourceId = new ResourceId();
newPlaylistItem.Snippet.ResourceId.VideoId = existingPlaylistItem.Snippet.ResourceId.VideoId;
newPlaylistItem.Snippet.ResourceId.Kind = existingPlaylistItem.Snippet.ResourceId.Kind;

await youTubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync();
其中,
newplaylitem
是我要插入的项目,
existingplaylitem
是频道上载播放列表中的现有项目。我只是复制值并更改播放列表id

此外,当在谷歌开发者文档网站上使用API浏览器时,一切正常(使用Web授权)。在Google开发者控制台中,我启用了所有API。也许问题是我缺少服务帐户类型所需的一些信息? 有人能帮我解决这个问题吗


这是我的源代码库。请求时第235行出现错误。

引用Google Youtube API官方文档:

服务帐户不适用于YouTube数据API调用,因为服务帐户需要关联的YouTube频道,并且您无法将新频道或现有频道与服务帐户关联。如果您使用服务帐户调用YouTube数据API,API服务器将返回一个错误,错误类型设置为unauthorized,原因设置为youtubeSignupRequired。


求你了

最简单的方法是进入应用程序的同意屏幕

通过添加YouTube作用域编辑应用程序(如果需要,可以添加更多作用域)。重新登录并再次测试播放列表功能


为我工作,我通过YouTube服务类获得了该帐户的播放列表

谢谢!。我查阅了很多文档,但没有找到这一个。