Google api 对google api进行身份验证时出现问题或应用程序出现问题

Google api 对google api进行身份验证时出现问题或应用程序出现问题,google-api,youtube-api,google-oauth,youtube-data-api,google-api-dotnet-client,Google Api,Youtube Api,Google Oauth,Youtube Data Api,Google Api Dotnet Client,所以,请注意,这是我第一次使用谷歌的API和开发人员控制台,如果我错过了一些经验丰富的谷歌开发人员认为是常识的东西,请原谅我。话虽如此。我正在尝试创建一个已安装的应用程序,它将在我的帐户下将视频上传到youtube。我在powershell中编写应用程序,因此在启动脚本时导入相应的google.Net库。在此基础上,我基本上使用了此处的示例,并将内容转换为powershell: Add-Type -AssemblyName mscorlib Add-Type -AssemblyName Syst

所以,请注意,这是我第一次使用谷歌的API和开发人员控制台,如果我错过了一些经验丰富的谷歌开发人员认为是常识的东西,请原谅我。话虽如此。我正在尝试创建一个已安装的应用程序,它将在我的帐户下将视频上传到youtube。我在powershell中编写应用程序,因此在启动脚本时导入相应的google.Net库。在此基础上,我基本上使用了此处的示例,并将内容转换为powershell:

Add-Type -AssemblyName mscorlib
Add-Type -AssemblyName System.Net.Http
Add-Type -AssemblyName System
Add-Type -AssemblyName System.Core
Add-Type -AssemblyName System.Numerics
Add-Type -AssemblyName System.Xml
Add-Type -AssemblyName System.Xml.Linq
Add-Type -AssemblyName System.Data
Add-Type -AssemblyName System.Runtime.Serialization
#the below command imports the following assemblies: Google.Apis.Auth.dll, Google.Apis.Auth.PlatformServices.dll, Google.Apis.Core.dll, Google.Apis.dll, Google.Apis.PlatformServices.dll, Google.Apis.YouTube.v3.dll
Get-ChildItem 'C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\*.dll' | % {[reflection.assembly]::LoadFrom($_.FullName)}
$vid = "C:\Users\whiggs\Documents\gery2.mp4"
#$file = [System.IO.File]::OpenRead("C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\client_id.json")
$filemode = [System.IO.FileMode]::Open
        $fileaccess = [System.IO.FileAccess]::Read
        $stream = New-object System.IO.FileStream -ArgumentList "C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\client_secret.json", $filemode, $fileaccess
        $googlebroker = New-object Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker
        $thing = [Google.Apis.Auth.OAuth2.GoogleClientSecrets]::Load($stream)
        [string[]]$scope = [Google.Apis.YouTube.v3.YouTubeService+ScopeConstants]::YoutubeUpload
        #$scope = [Google.Apis.YouTube.v3.YouTubeService+Scope]::YoutubeUpload
        $cancellation = [System.Threading.CancellationToken]::None
        $googlebroker = [Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker]::AuthorizeAsync($thing.Secrets, $scope, "<google_username>", $cancellation)
        $googlebroker.Wait()
        [Google.Apis.Auth.OAuth2.UserCredential]$cred = $googlebroker.Result
        $baseclient = new-object Google.Apis.Services.BaseClientService+Initializer
        $baseclient.HttpClientInitializer = $cred
        $baseclient.ApplicationName = "Contacts Tool"
        $service = New-Object Google.Apis.YouTube.v3.YouTubeService($baseclient)
        $video = New-Object Google.Apis.YouTube.v3.Data.Video
        $video.Snippet = New-Object Google.Apis.YouTube.v3.Data.VideoSnippet
        $video.Snippet.Title = "test"
        $video.Snippet.Description = "none"
        $video.Status = New-Object Google.Apis.YouTube.v3.Data.VideoStatus
        $video.Status.PrivacyStatus = "public"
        $vidstream = New-Object System.IO.FileStream -ArgumentList $vid, $filemode
        $request = $service.Videos.Insert($video, "public", $vidstream, "video/*")
        $task = $request.UploadAsync()
        $task.Wait()
        $vidstream.close()
        $vidstream.Dispose()
添加类型-AssemblyName mscorlib
添加类型-AssemblyName System.Net.Http
添加类型-AssemblyName系统
添加类型-AssemblyName System.Core
添加类型-AssemblyName系统.Numerics
添加类型-AssemblyName System.Xml
添加类型-AssemblyName System.Xml.Linq
添加类型-AssemblyName System.Data
添加类型-AssemblyName System.Runtime.Serialization
#下面的命令导入以下程序集:Google.api.Auth.dll、Google.api.Auth.PlatformServices.dll、Google.api.Core.dll、Google.api.dll、Google.api.PlatformServices.dll、Google.api.YouTube.v3.dll
获取ChildItem'C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\*.dll'|%{[reflection.assembly]::LoadFrom($\ uz.FullName)}
$vid=“C:\Users\whiggs\Documents\gery2.mp4”
#$file=[System.IO.file]::OpenRead(“C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\client\u id.json”)
$filemode=[System.IO.filemode]::打开
$fileaccess=[System.IO.fileaccess]::读取
$stream=New object System.IO.FileStream-ArgumentList“C:\Users\whiggs\Documents\SAPIEN\PowerShell Studio\Projects\youtube\client\u secret.json”、$filemode、$fileaccess
$googlebroker=新对象Google.api.Auth.OAuth2.GoogleWebAuthorizationBroker
$thing=[Google.api.Auth.OAuth2.GoogleClientSecrets]::Load($stream)
[string[]$scope=[Google.api.YouTube.v3.YouTubeService+ScopeConstants]::YoutubeUpload
#$scope=[Google.api.YouTube.v3.YouTubeService+scope]::YoutubeUpload
$cancellation=[System.Threading.CancellationToken]::无
$googlebroker=[Google.api.Auth.OAuth2.GoogleWebAuthorizationBroker]::AuthorizeAsync($thing.Secrets,$scope,“,$cancellation)
$googlebroker.Wait()
[Google.api.Auth.OAuth2.UserCredential]$cred=$googlebroker.Result
$baseclient=新对象Google.api.Services.BaseClientService+初始值设定项
$baseclient.HttpClientInitializer=$cred
$baseclient.ApplicationName=“联系人工具”
$service=新对象Google.api.YouTube.v3.YouTubeService($baseclient)
$video=新对象Google.api.YouTube.v3.Data.video
$video.Snippet=新对象Google.api.YouTube.v3.Data.VideoSnippet
$video.Snippet.Title=“测试”
$video.Snippet.Description=“无”
$video.Status=新对象Google.api.YouTube.v3.Data.VideoStatus
$video.Status.PrivacyStatus=“public”
$vidstream=New Object System.IO.FileStream-ArgumentList$vid,$filemode
$request=$service.Videos.Insert($video,“public”、$vidstream,“video/*”)
$task=$request.UploadAsync()
$task.Wait()
$vidstream.close()
$vidstream.Dispose()
我真的不需要包含代码,因为我知道它是正确编写的,因为没有生成异常。当我运行上述代码时,它运行到completion时不会生成异常,但是如果我查看存储在$task中的对象(type System.Threading.Tasks.task.task),而整个对象报告它将运行到完成,深入挖掘对象的“Result”属性会显示任务实际上失败,并进一步深入到“exception”属性提供以下错误消息:

The service youtube has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
Access Not Configured. YouTube Data API has not been used in project <snip> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=<snip> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. [403]
Errors [
    Message[Access Not Configured. YouTube Data API has not been used in project <snip> before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=<snip> then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.] Location[ - ] Reason[accessNotConfigured] Domain[usageLimits]
]

   at Google.Apis.Upload.ResumableUpload`1.<InitiateSessionAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Google.Apis.Upload.ResumableUpload.<UploadAsync>d__70.MoveNext()
youtube服务引发了一个异常:Google.GoogleAppeException:Google.API.Requests.RequestError
未配置访问权限。YouTube数据API以前未在项目中使用过或已被禁用。请访问以启用它https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project= 然后重试。如果您最近启用了此API,请等待几分钟,让操作传播到我们的系统,然后重试。[403]
错误[
Message[未配置访问权限。YouTube数据API以前未在project中使用过或已禁用。请访问以启用它https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project= 然后重试。如果您最近启用了此API,请等待几分钟,让操作传播到我们的系统,然后重试。]Location[-]原因[accessNotConfigured]域[usageLimits]
]
在Google.api.Upload.ResumableUpload`1.d_u25.MoveNext()上
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中
在Google.api.Upload.ResumableUpload.d_u70.MoveNext()上
因此,很明显,应用程序在配置或我对其进行身份验证的方式上存在某种问题。但是,正如您所看到的,我知道应用程序至少正在接收请求。因此,在做了这些研究之后,我对问题可能是什么进行了一些有根据的猜测,并且需要一些关于a)哪个)的输入其中(如果有)是实际问题,b)需要做些什么来纠正它。我的第一个猜测涉及我传递给Google.API.Auth.OAuth2.GoogleWebAuthorizationBroker类的“AuthorizationAsync”方法的参数。根据文档: “在此示例代码中,通过调用GoogleWebAuthorizationBroker.AuthorizationAsync方法创建了一个新的UserCredential实例。此静态方法获取客户机机密(或客户机机密的流)、所需的作用域、用户标识符、用于取消操作的取消令牌以及可选的数据存储。如果数据不正确
$googlebroker = [Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker]::AuthorizeAsync($thing.Secrets, $scope, "<google_username>", $cancellation)