- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用最新版本的 Google.Apis.YouTube.v3(截至 2014 年 1 月 15 日)执行一些 YouTube 视频交互。
我在以下方面做了一个 NuGet:
然后我尝试运行找到的代码:https://developers.google.com/youtube/v3/docs/playlistItems/list
但是,该代码具有以下引用,我似乎无法在任何最新的 NuGet 下载中找到这些引用...
使用 Google.Apis.Auth.OAuth2.DotNetOpenAuth;
使用 Google.Apis.Samples.Helper;
然后在代码顶部有以下注释,但这些链接没有给我任何用处。
/* 外部依赖、OAuth 2.0 支持和核心客户端库位于:*/
/* https://code.google.com/p/google-api-dotnet-client/wiki/APIs#YouTube_Data_API */
/* 另请参阅 Google.Apis.Samples.Helper 类的 Samples.zip 文件:*/
/* https://code.google.com/p/google-api-dotnet-client/wiki/Downloads */
我开始相信使用 C# 玩 YouTube 的最佳方式是使用旧版本的 YouTube.v3 代码库,这些代码库与人们似乎开始工作的示例一致。
任何帮助(尤其是来自 peleyal 的帮助)将不胜感激。也许我遗漏了一些明显的东西,需要被打败......
顺便说一句,我已经下载了我的客户端 secret json 文件并成功运行了 google-api-dotnet-client-1.7.0-beta.samples.zip
文件中包含的一些示例。然而,奇怪的是,该示例 zip 文件中缺少任何 YouTube 示例。该 zip 文件中还缺少 Google.Apis.Samples.Helper 类。
有没有人有一些有用的示例代码,可以使用截至 2014 年 1 月 14 日的最新 NuGet 代码与 YouTube 进行交互?
最佳答案
所以经过大量研究、挖掘和少一点头发,我想通了一些事情。
首先,登录“Google Cloud Console”。如果您使用的是 GAE(Google App Engine)并单击您的 GAE 项目并启用“YouTube 数据 API v3”,那么您一定会一无所获!相反,退出您的 GAE 项目,并创建一个名为“API 项目”的新项目。
然后在那个 项目中,启用所需的 API,您将开始获得更好的结果。结果好多了。首先尝试 YouTube 搜索。这使您只需插入您的 API key ,而不必弄乱 OAuth2,并且它需要更少的 dll,因此它是一个很好的起点。尝试如下操作:
YouTubeService youtube = new YouTubeService(new BaseClientService.Initializer() {
ApplicationName = "{yourAppName}",
ApiKey = "{yourApiKey}",
});
SearchResource.ListRequest listRequest = youtube.Search.List("snippet");
listRequest.Q = "Loeb Pikes Peak";
listRequest.MaxResults = 5;
listRequest.Type = "video";
SearchListResponse resp = listRequest.Execute();
foreach (SearchResult result in resp.Items) {
CommandLine.WriteLine(result.Snippet.Title);
}
请随意用常规控制台打印 stmts 替换 CommandLine。
接下来,转到 OAuth 2.0 并尝试让您的凭据无误地通过。您需要从“凭据”部分下的“Google Cloud Console”下载您的 OAuth JSON 文件。获得此文件后,将所有名为“client_secrets.json”的文件替换为下载的 json 文件的内容。为了获得工作授权,我发现我缺少 Microsoft.Threading.Tasks.Extensions.Desktop.dll,它是允许浏览器打开一个窗口以授予 native 应用程序访问权限的 dll YouTube 帐户。因此,如果您在授权部分遇到一些错误,请检查内部异常,这也可能是您的问题。
免责声明:下面显示的代码的下半部分来自:github.com/youtube/api-samples/blob/master/dotnet
UserCredential credential;
using (FileStream stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None,
new FileDataStore("YouTube.Auth.Store")).Result;
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Default Video Title";
video.Snippet.Description = "Default Video Description";
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
var filePath = @"REPLACE_ME.mp4"; // Replace with path to actual movie file.
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
videosInsertRequest.UploadAsync();
}
所以这是我的 2 美分值(value)。此外,您需要在 DotNetOpenAuth 和代码中执行 NuGet,将对 Google.Apis.Auth.OAuth2.DotNetOpenAuth 的任何“使用”调用替换为“使用 DotNetOpenAuth”。
希望这对其他人有帮助。重要的是弄清楚 GAE 与新项目的关系。一旦我弄明白了这一点,正常数量的研究就开始产生结果,而不是纯粹的挫败感!!
关于c# - 使用 C# 和 Google.Apis.YouTube.v3 列出 YouTube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21132531/
如何从单个输入字段中的逗号分隔值输出列表(无论是作为单个值还是作为数组)? 示例 用户在文本输入字段中输入以下内容:Steve、Bruce、Matt、Natasha、Peter 结果: 史蒂夫 布鲁斯
如何列出与 Jena 中的实例关联的所有对象属性? 例如:Person 有一个名为“hasVehicle”的对象属性,它与类 Vehicle 相关联 最佳答案 合适的 Jena 方法是 OntClas
如何列出与 Jena 中的实例关联的所有对象属性? 例如:Person 有一个名为“hasVehicle”的对象属性,它与类 Vehicle 相关联 最佳答案 合适的 Jena 方法是 OntClas
我知道 Python 是一种动态语言,但下面的代码让我很困扰。 我有下面的简单程序,它有一些辅助函数来包装命令执行。 EventLoaderToVerticaHelper 是一个有两个方法的辅助类,所
我有以下代码 public void saveProjects(List proj) throws DatabaseException { for (Project listItems: pr
我有一个列表,其中元素是: struct element { double priority; int value;
我看到对于 pull 请求的提交,根据文档最大限制为 250:List commits on a Pull Request如果 pull 请求超过 250 次提交,则建议使用另一个端点:List Co
我是 django 的新手,我想列出一个 django 项目的应用程序,例如: FeinCMS 我知道 startapp 会为应用程序创建目录结构。请问有没有函数或者文件可以获取应用列表。 以Fein
你能列出所有在 Hibernate 框架中使用的设计模式吗? 我了解一些设计模式,如 DAO、ORM 等。 如果可能的话,一些例子。 最佳答案 Hibernate 中使用的设计模式: 领域模型模式——
我正在尝试在终端中使用 psql 来查找数据库中所有可为空的列。如果我使用 select * from information_schema.check_constraints; 我得到如下信息 c
您可以使用以下步骤列出 WSO2 碳基产品使用的所有管理服务。 使用 OSGI 控制台启动服务器。转至 /bin 使用命令 shell 。 i) 例如:Linux sh wso2server.s
我想列出数据库中的所有表名。我的应用程序必须独立于 DBMS。不同的 DBMS 有不同的命令来列出表,例如: PstgreSQL: SELECT * FROM pg_catalog.pg_table
主要是为了我自己的启发,我试图列出当前 Emacs session 中加载的所有全局变量。我正在考虑做的是生成一个包含所有列出的功能的 HTML 文件。当然,定义函数、var 等的文件也很有用。 em
我如何定义 lists:append具有列表理解功能? 我想要类似的东西 1> append([[1, 2, 3], [a, b], [4, 5, 6]]). [1,2,3,a,b,4,5,6] 最佳
使用以下 Powershell 代码段,我可以获取当前用户的组成员名称: $groups = [System.Security.Principal.WindowsIdentity]::GetCurre
如何列出 Docker 容器的所有卷?我知道它应该很容易获得,但我找不到方法。 另外,是否可以获取已删除容器的卷并将其删除? 最佳答案 您可以使用 docker ps,获取容器 ID 并写入: $ d
来自微软独库: The "\\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace
这个问题在这里已经有了答案: 9年前关闭。 Possible Duplicate: Finding all Namespaces in an assembly using Reflection (Do
是否有命令行选项可以列出您的 Cucumber 测试套件中的所有标签? 例如,我想要这样的东西: cucumber --show-tags foo.feature 那会给我类似的东西: @ci @de
有没有一种快速的方法来列出为数据库定义的所有实际上没有被任何字段使用的 Firebird 域?我有一个包含许多表和许多域的大型数据库,似乎其中很多不再使用,所以我想是时候进行清理了! 我认为这可以通过
我是一名优秀的程序员,十分优秀!