I have an issue fetching an Ad performance report with the youtube analytics api with adType dimension, I get the following response:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Forbidden",
"reason" : "forbidden"
} ],
"message" : "Forbidden"
}
As specified in the documentation (https://developers.google.com/youtube/analytics/channel_reports#ad-performance-reports) I generated credentials with the scopes specified in the example:
List<String> scopes = Lists.newArrayList(
"https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly",
"https://www.googleapis.com/auth/youtube.readonly"
);
// Authorize the request.
Credential credential = Auth.authorize(scopes, "analyticsreports");
Then this is how I request the report:
public QueryResponse getAdPerformaceReportByVideo(String channelId, String videoId, String startDate, String endDate) throws IOException {
UserCredentials userCredentials = buildUserCredentials();
userCredentials.refresh();
final HttpRequestInitializer httpRequestInitializer = new HttpCredentialsAdapter(userCredentials);
final HttpTransport httpTransport = new NetHttpTransport();
final JsonFactory jsonFactory = new JacksonFactory();
YouTubeAnalytics youTubeAnalytics = new YouTubeAnalytics.Builder(httpTransport, jsonFactory, httpRequestInitializer)
.setApplicationName("myapp")
.build();
final YouTubeAnalytics.Reports.Query request = youTubeAnalytics.reports().query();
try {
final QueryResponse queryResponse = request.setStartDate(startDate)
.setEndDate(endDate)
.setIds("channel==" + channelId)
.setMetrics("grossRevenue,adImpressions,cpm")
.setDimensions("adType,day")
.setFilters("video==" + videoId)
.execute();
return queryResponse;
} catch (IOException e) {
throw new YoutubeInsightsException("", e);
}
}
private UserCredentials buildUserCredentials() {
return UserCredentials.newBuilder()
.setClientSecret(this.clientSecret)
.setClientId(this.clientId)
.setRefreshToken(this.youtubeRefreshToken)
.build();
}
I only use the refresh token to have a fresh access token on each request, this works very well with reports using all the other dimensions except for this one in particular.
Is there any other particular requirement to query this dimension?
I appreciate your help.
Thank you.