- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 youtube api v3 和 .NET 将视频上传到 youtube,但它会永远挂起调用 AuthorizeAsync。您还可以在以下位置查看代码:https://developers.google.com/youtube/v3/code_samples/dotnet
static void Main(string[] args)
{
Console.WriteLine("YouTube Data API: Upload Video");
Console.WriteLine("==============================");
try
{
new UploadVideo().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("Error: " + e.Message);
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", 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
});
最佳答案
我找到了解决方案。代码不起作用,因为应用程序托管在 IIS 上。 IIS 访问 %appdata% 文件夹内的文件夹可能存在问题。 token 文件默认保存在 %appdata% 文件夹中。我尝试更改对该文件夹的权限。我添加了 Everyone,DefaultAppPool,I_USER,... 但没有成功。还有更新版本的 Google.Apis (1.8.2) 允许完整路径( new FileDataStore(fullPath,true)) true 表示完整路径,但即使存在错误。无法使用该构造函数,因为我总是出错。所以我决定我的应用程序应该使用 IIS Express(实际上我创建了带有授权代码的新项目)。转到解决方案属性并将您的应用设置为使用 IIS Express。
从 https://console.developers.google.com 获取 cliendId(json 文件) (选择 Web 应用程序)并将 http://localhost:48372 (或任何您的应用程序端口使用)设置为 javascript 来源,并将 http://localhost:48372/authorize.aspx 设置为重定向 url。您还应该在互联网上找到如何使您的端口静态)。保存您的 clientId 文件。 (这一步你可能已经做过了)
当您使用 IIS express 时, AuthorizeAsync 方法应该没有问题。系统将提示您输入凭据并选择您的 youtube 帐户(如果您已经登录,则只需选择帐户)。当您授予您的应用权限时,您将被重定向到 authorize.aspx。您的授权 aspx 页面应创建新的 IAuthorization 流对象,并提供 Client Secret 属性和 DataStore 属性。使用 code= Request.Params["code"] 从 URL 读取代码并创建 UserCredential 对象。 youtubeService 的 HttpClientInitializer 属性是 UserCredential 类型。您应该使用的方法类似于 var usercredential= flow.SomeMethodWhichReceives("user",code,CancelletionToken.None)。之后,在您指定的 FileDataStore 文件夹中生成包含刷新 token 的文件。
当您拥有刷新 token 时,您可以做任何您想做的事情,因为刷新 token 应该永远持续(除非手动撤销)。有一种方法允许从 refreshtoken 获取用户凭据,例如 flow.getAccessTokenfromRefreshToken("user","your_refresh_token_string")
因此,当您拥有刷新 token 并使用最后一种方法时,您将能够访问 google youtube api。您还可以使用这种方法将其他用户上传到您的 youtube 帐户。如果您对用户放入您帐户的内容感到满意,您可以随时将他们上传的视频设为私有(private),并在您验证它们时将其更改为公开。
google youtube api 中的某些方法需要 OAUTH2 身份验证(从客户端密码获取刷新 token -> 从刷新 token 获取访问 token ...),例如上传视频,但有些方法(例如 getvideos)不需要。您可以向您的 youtubeService 构造器提供 API key ,而不是 UserCredential
编辑:还有一个我忘了提到的问题(对于那些认为这就是全部的人)。当您授予应用访问 google api 的权限时(就在您被重定向到 authorize.aspx 之前),您将收到错误 redirect_url mismatch,因为 url 参数 redirect_url 中的某个位置与您在 ClientId 中提供的重定向 url 不匹配json,(端口不同,至少,出于某种原因)。更改此参数,使其与您在 clientId json 中提供的重定向 url 匹配。
关于.net - googleWebAuthorizationBroker.AuthorizeAsync 永远挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25629183/
我尝试使用 youtube api v3 和 .NET 将视频上传到 youtube,但它会永远挂起调用 AuthorizeAsync。您还可以在以下位置查看代码:https://developers
GoogleWebAuthorizationBroker.AuthorizeAsync() 在(农场,4.5 NET)暂存服务器上失败,但在本地服务器上运行良好。我已按照帮助热线上的每个代码进行操作,
我们的网站需要从后台代码(asp.net mvc 应用程序)上传视频到youtube。我正在尝试获取 google 凭据,但是当我调用 AuthorizeAsync 时,应用程序只是挂起。我到处寻找解
我有一个 C# .net Web 应用程序,用于将视频上传到 Youtube。这在大约 6 个月前有效,但现在已停止工作。当我在本地计算机上通过 Visual Studio 启动网站时,以下代码挂起:
我正在编写一个 C# 桌面应用程序,可以将其输出复制到用户的 Google 云端硬盘。但是,当我尝试使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 授
问题已更新,以便更好地解释我遇到的问题, 只要我有这个 Controller , [Authorize] public class IdeaManagementController :
我正在尝试更改我们对 .net 客户端库的旧 rest 调用,我有两个相关的问题/问题...... 此页面上的示例应用程序 https://developers.google.com/api-clie
我正在尝试使用 Google Calendar API在我的非 MVC .NET Web 应用程序中。 (这似乎是一个重要的区别。) 我尝试使用来自 this example 的代码在谷歌和 this
我有一个使用 adsense api 的报告应用程序。 我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync 进行身份验证。 当我在本地使用它时,它工作正
我有一个我编写的 C# 库,它提供了一些辅助函数来访问 Google 云端硬盘。 服务构造函数调用 AuthorizeAsync 如下: // get access token var credent
我在将我的代码发布到 IIS7.0 后遇到 GoogleWebAuthorizationBroker.AuthorizeAsync 超时问题。 通过我的开发环境,一切都按预期工作。我看到了 Googl
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
我正在尝试使用 Azure 托管 Web 应用程序执行 OAuth2,但我无法使用服务帐户(此处有许多可用的解决方案,但它们都坚持服务帐户/证书),而我需要用户由 Google 进行身份验证和授权。
服务器设置: ASP.NET 表单在 .net 4.5.1 集成管道上运行,在服务器 2012 上的 iis8 上运行。 我正在尝试从谷歌的 GoogleWebAuthorizationBroker
当在 Windows 10 桌面/移动设备上运行时,此代码在我的 UWP 应用程序中运行良好,但在 Xbox One 上我收到错误: 我的 C# 代码: credential = await Goog
我在尝试让 MVC5 应用程序在部署时与 Google Mirror API(或与此相关的任何 Google API)一起工作时遇到了一个奇怪的问题。 这是我努力工作的代码: UserCredenti
我正在使用 GoogleWebAuthorizationBroker.AuthorizeAsync() 为 GoogleDrive 授权用户。 它适用于控制台或 UI 应用程序,但如果该方法在 Win
环境:.net 4.5.1 集成管道上的 ASP.NET 简单 Web 应用程序在服务器 2012 上的 iis8 上运行,不遵循 MVC。 我正在尝试从谷歌的 GoogleWebAuthorizat
我正在将 Google token 转换为 json 字符串格式并将该字符串存储在数据库中。 现在在谷歌驱动器中上传文件时,我想在 GoogleWebAuthorizationBroker.Autho
我是一名优秀的程序员,十分优秀!