当前位置: 首页 > 编程语言 > C#

如何正确validation适用于.NET的YouTube v3 Google API的Google帐户分享

时间:2023-04-10 15:46:53 C#

C#学习教程:如何为适用于.NET的YouTubev3GoogleAPI正确验证Google帐户/v3/code_samples/dotnet)我正在尝试创建一个可以恢复上传到YouTube的应用。我的应用程序使用我的客户端密码和客户端ID在GoogleAPI控制台上注册。这是我用来认证的方法:UserCredentialcredential;使用(FileStreamstream=newFileStream("client_secrets.json",FileMode.Open,FileAccess.Read)){credential=awaitGoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,new[]{YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeUpload},"[my_username]",CancellationToken.None,newFileDataStore("YouTube.ListMyLibrary"));进程在等待调用时挂起。client_secrets.json文件加载正常(单独测试)。但是,在调用AuthorizeAsync时,我在它挂起之前得到以下输出:mscorlib.dll中发生类型为“System.IO.FileNotFoundException”的第一次机会异常Microsoft中发生类型为“System.IO.FileNotFoundException”的第一次机会异常。Threading.Tasks.dll类型为“System.IO.FileNotFoundException”的第一次机会异常发生在Microsoft.Threading.Tasks.dll中类型为“System.IO.FileNotFoundException”的第一次机会异常发生在mscorlib.dll中第一次机会异常为mscorlib.dll中出现“System.IO.FileNotFoundException”类型我完全不知道它在寻找什么文件。我看过其他几个示例,但完全不知道如何执行此操作。似乎没有明确的方法来验证Youtubev3api。任何帮助将不胜感激!这应该工作UserCredential凭据;使用(varstream=newFileStream("client_secrets.json",FileMode.Open,FileAccess.Read)){GoogleWebAuthorizationBroker.Folder="Tasks.Auth.Store";credential=GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,new[]{YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeUpload},"user",CancellationToken.None,newFileDataStore("YouTube.Auth.Store"))。结果;https://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FTasks.ASP.NET.SimpleOAuth2参考这个链接..它对我有用..只需添加一个包含您的客户端ID和客户端密码的json文件,例如:{"web":{"client_id":"yourclientID""client_secret":"yourclientsecret"}}以上是C#学习教程:如何正确验证YouTubev3GoogleAPIfor.NET的Google帐户共享的所有内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多加关注——GoogleAuthorizationCodeFlow流程;varassembly=Assembly.GetExecutingAssembly();使用(varstream=assembly.GetManifestResourceStream("Tasks.ASP.NET.SimpleOAuth2.client_secrets.json")){flow=newGoogleAuthorizationCodeFlow(newGoogleAuthorizationCodeFlow.Initializer{DataStore=newFileDataStore("Tasks.ASP.NET.Sample.Store"),ClientSecretsStream=stream,Scopes=new[]{TasksService.Scope.TasksReadonly}});}varuri=Request.Url.ToString();varcode=Request["code"];if(code!=null){vartoken=flow.ExchangeCodeForTokenAsync(UserId,code,uri.Substring(0,uri.IndexOf("?")),CancellationToken.None).Result;//提取正确的状态。varoauthState=AuthWebUtility.ExtracRedirectFromState(flow.DataStore,UserId,Request["state"]).Result;Response.Redirect(oauthState);}else{varresult=newAuthorizationCodeWebApp(flow,uri,uri).AuthorizeAsync(UserId,CancellationToken.None).Result;if(result.RedirectUri!=null){//将用户重定向到授权服务器.Response.Redirect(result.RedirectUri);}else{//数据存储包含用户凭证,所以用户ha已经通过身份验证。service=newTasksService(newBaseClientService.Initializer{ApplicationName="TasksAPISample",HttpClientInitializer=result.Credential});}}本文收集自网络,不代表立场。如涉及侵权请点击维权联系管理会员删除如需转载请注明出处: