0

We are trying to retrieve Youtube analytics data for our own channel. We're using GTLQueryYouTubeAnalytics. This is an iPhone App written in Swift using Xcode 6

This is what we have:

var scope = "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/yt-analytics-monetary.readonly https://www.googleapis.com/auth/yt-analytics.readonly https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtube.readonly"
var vc = GTMOAuth2ViewControllerTouch(scope: scope, clientID: clientID, clientSecret: clientSecret, keychainItemName: kKeyChainItemName, delegate: self, finishedSelector:Selector("authentication:finishedWithAuth:error:"))


In authentication(){

    ....
    ....
    // On Success
    service = GTLServiceYouTube()
    service.authorizer = finishedWithAuth

    // Channel is my Channel ID
    var newQuery: GTLQueryYouTubeAnalytics = GTLQueryYouTubeAnalytics.queryForReportsQueryWithIds("channel==*****", startDate: "2014-10-15", endDate: "2014-10-16", metrics: "views,likes,shares,comments") as GTLQueryYouTubeAnalytics

    var ticket1 = GTLServiceTicket()
    ticket1 = service.executeQuery(newQuery, completionHandler: { (ticket: GTLServiceTicket!, object: AnyObject!, error: NSError!) -> Void in

        println("Analytics: \(object) or \(error)")

    })

}

This is my output:

Analytics: nil or Error Domain=com.google.GTLJSONRPCErrorDomain Code=404 "The operation couldn’t be completed. (Not Found)" UserInfo=0x***** {error=Not Found, NSLocalizedFailureReason=(Not Found), GTLStructuredError=GTLErrorObject 0x7f8e43ddc9b0: {message:"Not Found" data:[1] code:404}}

What are we missing here? We ran a previous query for the YouTubeDataAPI and that worked well.

Any thoughts appreciated!

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142

2 Answers2

0

The scope does not make sense. It should just contain one url e.g.

var scope = "https://www.googleapis.com/auth/youtube"
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
0

Thanks Dharmesh and Anthony, but the scope wasn't it. Scope expects a "String", and thus, the spaces is how Google expects it.

The root cause of the issue was the Service used. The correct service to be used is:

service = GTLServiceYouTubeAnalytics()