2
votes

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.

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);

                             }];

the server returns:

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?

I am using the sample youtube app.

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}

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

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

200 OK

  • Hide headers -

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"
   }
  }
 }
}

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"
}

1
if you are doing some quick testing you an make xcode ignore the warning for [GTMHTTPFetcher setLoggingEnabled:YES]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" + (void)setLoggingEnabled:(BOOL)flag { gIsLoggingEnabled = flag; } #pragma clang diagnostic popZsolt
publisherRequired seems to be the issue.Zsolt
developers.google.com/youtube/v3/docs/errors - to look up errors based on the descriptionZsolt

1 Answers

2
votes

The solution was to replace:

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

with this:

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