نماذج تعليمات برمجية بلغة Java

تتوفّر عيّنات الرموز التالية التي تستخدم مكتبة برامج Google APIs للحساب Java في YouTube Reporting API وYouTube Analytics API. يمكنك تنزيل نماذج الرموز هذه من المجلد java في مستودع نماذج الرموز البرمجية لواجهات برمجة تطبيقات YouTube على GitHub.

التقارير المجمّعة

استرداد التقارير

يوضح هذا النموذج كيفية استرداد التقارير التي تم إنشاؤها بواسطة وظيفة محددة. وهو يستدعي الطريقة jobs.list لاسترداد وظائف إعداد التقارير. بعد ذلك، تطلب طريقة reports.list مع ضبط المَعلمة jobId على معرّف وظيفة محدّد لاسترداد التقارير التي أنشأتها تلك المهمة. أخيرًا، تطبع العيّنة عنوان URL للتنزيل لكلّ تقرير.

/*
 * 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