0

I tried to execute You-tube analytics in java, using the sample java code available in git hub.The sample code allows me to get user consent page where I have allowed the access and while trying to execute the query using "reports().query(" ").execute() I am getting 404 resource not found response.

When executing the below method I am getting 404 not found exception:

private static ResultTable executeViewsOverTimeQuery(YouTubeAnalytics analytics,
                                                     String id) throws IOException {

    return analytics.reports()
            .query("channel==" + id,     // channel id
                    "2020-01-14",         // Start date.
                    "2020-01-16",         // End date.
                    "views,uniques")      // Metrics.
            .setDimensions("day")
            .setSort("day")
            .execute();
}

When I tried the same in API explorer it gives returns 200 ok response.

enter image description here

API Explorer URL: https://apis-explorer.appspot.com/apis-explorer/#p/youtubeAnalytics/v2/youtubeAnalytics.reports.query

Git hub code URL : https://github.com/youtube/api-samples/tree/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline/analytics

Console Log:

Jan 16, 2020 7:12:08 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly

WARNING: unable to change permissions for everybody: C:\Users\yoga.oauth-credentials

Jan 16, 2020 7:12:08 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly

WARNING: unable to change permissions for owner: C:\Users\yoga.oauth-credentials

2020-01-16 19:12:08.993:INFO::Logging to STDERR via org.mortbay.log.StdErrLog

2020-01-16 19:12:08.994:INFO::jetty-6.1.26

2020-01-16 19:12:09.012:INFO::Started SocketConnector@localhost:8080

Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/yt-analytics.readonly%20https://www.googleapis.com/auth/youtube.readonly

Attempting to open that address in the default browser now...

2020-01-16 19:12:21.400:INFO::Stopped SocketConnector@localhost:8080

Default Channel: xxxxxxx@gmail.com ( UCxxxxxxxxxxxxxxxxxxxxx )

IOException: 404 Not Found

Not Found

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

Not Found

at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1056)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.api.services.samples.youtube.cmdline.analytics.YouTubeAnalyticsReports.executeViewsOverTimeQuery(YouTubeAnalyticsReports.java:134)
at com.google.api.services.samples.youtube.cmdline.analytics.YouTubeAnalyticsReports.main(YouTubeAnalyticsReports.java:103)
yoganandh
  • 247
  • 1
  • 6
  • 20

1 Answers1

0

Have you tried to set the startDate and endDate, as well as the other parameters, using the proper API instead of passing them to the query() method?

Something like:

private static ResultTable executeViewsOverTimeQuery(YouTubeAnalytics analytics,
                                                 String id) throws IOException {

return analytics.reports()
        .query()
        .setEndDate("2020-01-16")
        .setIds("channel==" + id)
        .setMetrics("views,uniques")
        .setStartDate("2020-01-14")
        .setDimensions("day")
        .setSort("day")
        .execute();
}

Here you can find similar examples: reports-query-examples