Les exemples de code suivants, qui utilisent la bibliothèque cliente des API Google pour Java, sont disponibles pour YouTube Reporting API et l'API YouTube Analytics. Vous pouvez télécharger ces exemples de code à partir du dossier java du dépôt d'exemples de code des API YouTube sur GitHub.
-
Rapports groupés (API YouTube Reporting)
-
Rapports sur les requêtes ciblées (API YouTube Analytics)
Rapports groupés
Récupérer des rapports
Cet exemple montre comment récupérer des rapports créés par une tâche spécifique. Elle appelle la méthode jobs.list pour récupérer les tâches de création de rapports. Il appelle ensuite la méthode reports.list avec le paramètre jobId défini sur un ID de tâche spécifique pour récupérer les rapports créés par cette tâche. Enfin, l'exemple affiche l'URL de téléchargement pour chaque rapport.
/* * Copyright (c) 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ package com.google.api.services.samples.youtube.cmdline.reporting; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import com.google.api.client.http.GenericUrl; import com.google.api.services.samples.youtube.cmdline.Auth; import com.google.api.services.youtubereporting.YouTubeReporting; import com.google.api.services.youtubereporting.YouTubeReporting.Media.Download; import com.google.api.services.youtubereporting.model.Job; import com.google.api.services.youtubereporting.model.ListJobsResponse; import com.google.api.services.youtubereporting.model.ListReportsResponse; import com.google.api.services.youtubereporting.model.Report; import com.google.common.collect.Lists; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; import javax.print.attribute.standard.Media; /** * This sample retrieves reports created by a specific job by: * * 1. Listing the jobs using the "jobs.list" method. * 2. Retrieving reports using the "reports.list" method. * * @author Ibrahim Ulukaya */ public class RetrieveReports { /** * Define a global instance of a YouTube Reporting object, which will be used to make * YouTube Reporting API requests. */ private static YouTubeReporting youtubeReporting; /** * Retrieve reports. * * @param args command line args (not used). */ public static