gpt4 book ai didi

ios google+ api youtube 订阅 channel

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:18 27 4
gpt4 key购买 nike

我正在尝试为用户订阅 YouTube channel 。因此,用户登录到 iOS 应用程序,点击订阅,然后我会为用户订阅一个预定义的 channel 。因此,我创建了一个启用了 YouTube 数据 API v3 服务的应用程序。

范围:kGTLAuthScopeYouTube

GTLServiceYouTube *service = self.youTubeService;

GTLYouTubeSubscriptionSnippet* snippet = [GTLYouTubeSubscriptionSnippet object];
snippet.channelId = @"UCGRjJrpD2bmk9Ilq6nq80qg";

GTLYouTubeSubscription* subscription = [GTLYouTubeSubscription object];
subscription.snippet = snippet;

GTLQueryYouTube *query = [GTLQueryYouTube queryForSubscriptionsInsertWithObject:subscription part:@"contentDetails,snippet"];

[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeSubscription *subscription,
NSError *error) {
/* Callback */
NSLog(@"subscription:%@", subscription);
NSLog(@"error:%@", error);

}];

服务器返回:

error:Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32500 "The operation couldn’t be completed. (Required)" UserInfo=0x1005d3c20 {error=Required, NSLocalizedFailureReason=(Required), GTLStructuredError=GTLErrorObject 0x10054faa0: {message:"Required" data:[1] code:-32500}}

知道为什么会发生这种情况吗?

我正在使用示例 YouTube 应用。

https://developers.google.com/youtube/v3/docs/subscriptions/insert#examples 上的示例 url工作正常,据我所知,我在 objc 代码中做了同样的事情。

发布https://www.googleapis.com/youtube/v3/subscriptions?part=contentDetails%2Csnippet&fields=snippet&key= {YOUR_API_KEY}

内容类型:application/json授权:不记名ya29.AHES6ZQSBniofZhyVX4kfCn0-gVKKeiGayMcQHjTfWxMyffndRus7wX-JavaScript-User-Agent:Google API 资源管理器

{ “片段”:{ “资源编号”:{ “channelId”:“UCDPM_n1atn2ijUwHd0NNRQw” } }

200 好

  • 隐藏标题 -

缓存控制:无缓存、无存储、max-age=0、必须重新验证内容编码:gzip内容长度:286内容类型:application/json;字符集=UTF-8日期:2013 年 6 月 14 日星期五 11:28:26 GMTEtag:“2vd4g3cVsHAtTj​​JSdUMaBo1PBVE/Rv5ixqWURoAy7lbp6z3jpkm7IOE”过期时间:1990 年 1 月 1 日星期五 00:00:00 GMTPragma:无缓存服务器:GSE

{
"snippet": {
"publishedAt": "2013-06-14T11:28:26.000Z",
"title": "ColdplayVEVO",
"description": "",
"resourceId": {
"kind": "youtube#channel",
"channelId": "UCDPM_n1atn2ijUwHd0NNRQw"
},
"channelId": "UCQIKfhQEozSerNr3go189mw",
"thumbnails": {
"default": {
"url": "https://i1.ytimg.com/i/DPM_n1atn2ijUwHd0NNRQw/1.jpg?v=c2f0dd"
},
"high": {
"url": "https://i1.ytimg.com/i/DPM_n1atn2ijUwHd0NNRQw/mq1.jpg?v=c2f0dd"
}
}
}
}

更新 1启用登录 - 请参阅下面的详细信息youtube.subscriptions.insert

2013-06-19 08:45:52 +0000
Request: POST https://www.googleapis.com/rpc?prettyPrint=false
Request headers:
Accept: application/json-rpc
Authorization: Bearer _snip_
Cache-Control: no-cache
Content-Type: application/json-rpc; charset=utf-8
User-Agent: com.boxonline.tpp.bol.think/1.0 google-api-objc-client/2.0 MacOSX/10.8.3 (gzip)

Request body: (214 bytes)
{
"jsonrpc" : "2.0",
"method" : "youtube.subscriptions.insert",
"id" : "gtl_1",
"params" : {
"fields" : "snippet",
"part" : "contentDetails,snippet",
"resource" : {
"snippet" : {
"channelId" : "UCGRjJrpD2bmk9Ilq6nq80qg"
}
}
},
"apiVersion" : "v3"
}

Response: status 200
Response headers:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 131
Content-Type: application/json; charset=UTF-8
Date: Wed, 19 Jun 2013 08:45:52 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block

Response body: (152 bytes)
{
"error" : {
"message" : "Required",
"data" : [
{
"reason" : "publisherRequired",
"message" : "Required",
"domain" : "youtube.subscription"
}
],
"code" : -32500
},
"id" : "gtl_1"
}

最佳答案

解决方案是替换:

GTLYouTubeSubscriptionSnippet* snippet = [GTLYouTubeSubscriptionSnippet object];
snippet.channelId = @"UCGRjJrpD2bmk9Ilq6nq80qg";

用这个:

GTLYouTubeSubscriptionSnippet* snippet = [GTLYouTubeSubscriptionSnippet object];
GTLYouTubeResourceId* resourceObject = [GTLYouTubeResourceId object];
resourceObject.channelId = @"UCGRjJrpD2bmk9Ilq6nq80qg";

关于ios google+ api youtube 订阅 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17186151/

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