gpt4 book ai didi

.net - Google API DotNet Youtube 播放列表失败,没有 PlaylistID

转载 作者:行者123 更新时间:2023-12-03 06:30:18 24 4
gpt4 key购买 nike

谢谢你,我真的很感谢你的帮助!

我正在尝试让 .NET Google API 客户端工作,但我什至无法弄清楚如何做一些简单的事情。我的目标是有一个网页,在顶部加载一个 youtube 播放列表播放器,并在其下方列出有关其他轨道的信息。

你能帮我克服让客户运行的第一个困难吗?

我有一个 .NET 4.0 网站实例,并且通过 nuget 包管理器安装了 DotNet Google API。我认为问题在于我无法弄清楚如何将 PlaylistID 传递给客户端请求。我可以在下面的代码中的哪个位置指定 PlaylistID?

Imports Google.Apis.YouTube.v3
Imports Google.Apis.YouTube.v3.Data

Dim Initialiser As New Google.Apis.Services.BaseClientService.Initializer()
Initialiser.ApiKey = "My Server API Key"
Dim Service As YouTubeService = New YouTubeService(Initialiser)
Dim Result As PlaylistItemListResponse
Result = Service.PlaylistItems().List("snippet").Execute()
If Not Result.Items Is Nothing Then
Dim XPathDocument As System.Xml.XPath.XPathDocument = GenerateXPathDocument(Result.Items)
SamplerXml.XPathNavigator = XPathDocument.CreateNavigator
End If

错误输出为:
2014-01-21 12:14:30.1894 Error ASP.global_asax 
Application_Error: GET /sampler/120
BaseExceptionType: Google.GoogleApiException
Type=System.Web.HttpUnhandledException
Message=Exception of type 'System.Web.HttpUnhandledException' was thrown.
Stack=
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.templates_sampler_default_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Type=Google.GoogleApiException
Message=Google.Apis.Requests.RequestError
No filter selected. [400]
Errors [
Message[No filter selected.] Location[ - parameter] Reason[missingRequiredParameter] Domain[youtube.parameter]
]

Stack=
at Google.Apis.Requests.ClientServiceRequest`1.Execute() in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 93
at SiteCode.Templates.Sampler.Page_Load(Object sender, EventArgs e) in C:\svn-work\playlistproject\site\templates\sampler\Default.aspx.vb:line 54
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

感谢您的帮助和时间!

最佳答案

答案很简单。

        Dim Initialiser As New Google.Apis.Services.BaseClientService.Initializer()
Initialiser.ApiKey = "My API Key"
Dim Service As Google.Apis.YouTube.v3.YouTubeService = New YouTubeService(Initialiser)
Dim Result As Google.Apis.YouTube.v3.Data.PlaylistItemListResponse
Dim ListRequest As Google.Apis.YouTube.v3.PlaylistItemsResource.ListRequest
ListRequest = Service.PlaylistItems().List("snippet")
ListRequest.PlaylistId = "My Playlist ID"
Result = ListRequest.Execute()
If Not Result.Items Is Nothing Then
Dim XPathDocument As System.Xml.XPath.XPathDocument = GenerateXPathDocument(Result.Items)
SamplerXml.XPathNavigator = XPathDocument.CreateNavigator
End If

所以我必须创建列表请求,然后设置播放列表 ID,然后执行请求。有时候我真的很慢...

我希望这对其他人有帮助!

关于.net - Google API DotNet Youtube 播放列表失败,没有 PlaylistID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21268500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com