ios google + api youtube订阅频道 [英] ios google+ api youtube subscribe to a channel

查看:108
本文介绍了ios google + api youtube订阅频道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将用户订阅youtube频道.因此,用户登录到iOS应用程序,单击订阅",然后我将为该用户订阅预定义的频道. 因此,我有一个启用了YouTube数据API v3服务的应用程序.

I am trying to subscribe a user to a youtube channel. So the user logs in to an iOS app, hits subscribe, and I would subscribe the user to a predefined channel. So I have an app created with the YouTube Data API v3 service enabled.

范围:kGTLAuthScopeYouTube

scope: 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}}

任何想法为什么会发生这种情况?

Any ideas why would this happen?

我正在使用示例youtube应用.

I am using the sample youtube app.

https://developers.google.com/上的示例网址youtube/v3/docs/subscriptions/insert#examples 可以正常工作,并且据我所知,我在objc代码中正在做相同的事情.

The sample url on https://developers.google.com/youtube/v3/docs/subscriptions/insert#examples works correctly and from what I can tell I am doing the same thing above in objc code.

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

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

内容类型:application/json 授权:Bearer ya29.AHES6ZQSBniofZhyVX4kfCn0-gVKKeiGayMcQHjTfWxMyffndRus7w X-JavaScript-User-Agent:Google API资源管理器

Content-Type: application/json Authorization: Bearer ya29.AHES6ZQSBniofZhyVX4kfCn0-gVKKeiGayMcQHjTfWxMyffndRus7w X-JavaScript-User-Agent: Google APIs Explorer

{ 摘录":{ "resourceId":{ "channelId":"UCDPM_n1atn2ijUwHd0NNRQw" } } }

{ "snippet": { "resourceId": { "channelId": "UCDPM_n1atn2ijUwHd0NNRQw" } } }

200好

  • 隐藏标题-

缓存控制:无缓存,无存储,最大年龄= 0,必须重新验证 内容编码:gzip 内容长度:286 内容类型:application/json;字符集= UTF-8 日期:2013年6月14日,星期五,格林尼治标准时间 Etag:"2vd4g3cVsHAtTj​​JSdUMaBo1PBVE/Rv5ixqWURoAy7lbp6z3jpkm7IOE" 过期:1990年1月1日星期五格林尼治标准时间 语法:无快取 服务器:GSE

Cache-Control: no-cache, no-store, max-age=0, must-revalidate Content-Encoding: gzip Content-Length: 286 Content-Type: application/json; charset=UTF-8 Date: Fri, 14 Jun 2013 11:28:26 GMT Etag: "2vd4g3cVsHAtTjJSdUMaBo1PBVE/Rv5ixqWURoAy7lbp6z3jpkm7IOE" Expires: Fri, 01 Jan 1990 00:00:00 GMT Pragma: no-cache Server: 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

UPDATE 1 Enabled loggin - see details below 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订阅频道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆