我正在使用Google的Oauth 2.0通过我们的服务器将视频上传到Youtube.我的客户ID是"服务帐户".我下载了json密钥并将其添加到我的解决方案中.
这是相关代码:
private async Task Run(string filePath)
{
UserCredential credential;
var keyUrl = System.Web.HttpContext.Current.Server.MapPath("~/content/oauth_key.json");
using (var stream = new FileStream(keyUrl, FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到此错误:应设置至少一个客户端机密(已安装或Web).
但是,在我的json中没有"客户秘密":
{ …Run Code Online (Sandbox Code Playgroud)