Google 디스플레이 및 Video 360은 항목 읽기 파일을 자동으로 저장 Google Cloud Storage에 저장 이러한 파일은 다음 사용자만 액세스할 수 있습니다. 액세스할 수 있습니다.
프로젝트 만들기
다음과 같이 프로젝트를 만들고 구성합니다.
- Google API 콘솔 지원 API 페이지로 이동합니다.
아직 Google에 로그인하지 않은 경우 로그인하라는 메시지가 표시됩니다.
- 프로젝트 드롭다운에서 기존 프로젝트를 선택하거나 새 프로젝트를 만듭니다.
- 기존 프로젝트가 여러 개 있는 경우 프로젝트를 선택해야 합니다. Google Cloud Storage를 활성화하려는 계정 이름을 선택한 다음 계속을 클릭합니다.
- 또는 프로젝트가 없는 경우 새 프로젝트 만들기를 선택하고 프로젝트 이름을 입력한 다음 만들기를 선택합니다.
참고: 일부 리소스 식별자는 (예: 프로젝트 ID)는 프로젝트 수명 이후에도 보존될 수 있습니다. 따라서 민감한 정보는 리소스에 저장하지 않는 것이 좋습니다. 사용됩니다.
- 사용 설정된 API 목록에 Google Cloud Storage 구성요소가 나열되어 있는지 확인합니다.
목록에 없으면 Google API 탭을 클릭하고 Google Cloud를 검색하여 선택합니다.
API 사용 설정을 클릭합니다.
대부분의 프로젝트에서는 Google Cloud Storage 구성요소가 이미 사용 설정되어 있습니다. 다음을 계획하는 경우 JSON API를 사용하여 Google Cloud Storage에 액세스한 다음 Google Cloud Storage JSON API가 사용 설정되어 있는지도 확인해야 합니다.
- 프로젝트에 결제를 사용 설정합니다.
Google Cloud Storage를 사용하려면 먼저 프로젝트를 아직 완료하지 않았다면 지금 완료합니다. 결제를 사용 설정하는 것이 요금이 청구되지 않습니다. 자세한 내용은 가격 책정을 참조하세요.
- Cloud Storage 프로젝트에서 왼쪽 상단의 갤러리 메뉴를 클릭한 다음 결제를 선택합니다.
- 아직 결제 계정이 없는 경우 다음 안내를 따르세요. 새 결제 계정을 만듭니다.
- 기존 결제 계정이 있는 경우 선택한 다음 계정 설정을 선택합니다.
Google API 콘솔에서 동일한 프로젝트 내에서 다음 섹션으로 이동합니다.
Cloud Storage에 대한 액세스 설정
필요한 프로젝트 내의 Google API 콘솔에서 왼쪽 상단에서 API 및 서비스를 선택한 다음 사용자 인증 정보를 클릭합니다. 일 사용자 인증 정보 페이지에서 서비스 계정 키를 찾습니다.
서비스 계정 키 이메일 주소를 찾습니다.
- 서비스 계정 키 섹션의 오른쪽에 있는 서비스 계정 관리 링크를 선택합니다.
- 이메일 주소는 권한 페이지에서 볼 수 있습니다.
서비스 계정 키가 없는 경우 새 서비스 계정을 만듭니다.
- 사용자 인증 정보 만들기 드롭다운을 선택한 다음 서비스 계정 키를 선택합니다.
- 서비스 계정 드롭다운에서 새 서비스 계정을 선택합니다.
- 서비스 계정의 이름을 입력합니다. 서비스 계정 ID는 자동으로 생성할 수 있습니다
- 서비스 계정 ID(
gserviceaccount.com
이메일 주소)를 기록해 둡니다. 만들기를 선택한 후 사용자 인증 정보 페이지에 표시되지 않습니다. - 키 유형 섹션에서 JSON을 선택합니다.
- 만들기를 클릭합니다. 계정의 공개 키/비공개 키 쌍이 있는 JSON 파일은 다운로드 폴더에 있습니다. 이 키는 API에 대해 애플리케이션을 인증하는 데 사용되며 API에 보내는 모든 요청에 서명합니다 생성된 JSON 파일을 안전한 장소에 저장합니다. 애플리케이션이 액세스할 수 있는 위치여야 합니다.
디스플레이 및 Video 360 지원팀의 항목 읽기 파일 사용 설정 요청 및/또는 Google Bid Manager API입니다.
지원팀에서 액세스를 확인한 후 전용 Google 그룹을 만듭니다. (또는 그룹)를 만들고 Display &Video 360에서 다음 필드를 Video 360 파트너 세부정보 (사용자는 액세스 권한이 있는 사용자는 다음과 같은 업데이트를 수행할 수 있습니다.
- 로그 읽기 Google 그룹
읽기 전용 그룹에는 파일을 읽고 스토리지 버킷의 콘텐츠를 나열할 수 있는 권한만 있습니다. - 로그 관리 Google 그룹
관리 그룹은 읽기 전용 그룹의 모든 권한을 가지고 있지만 변경할 수도 있습니다. 액세스할 수 있습니다 관리 그룹에도 권한이 없음 버킷 ACL을 변경할 수 없고 파일을 생성, 수정 또는 삭제할 권한도 없습니다.
Google 그룹을 추가한 후 필요에 따라 Google 그룹에 사용자를 추가하거나 삭제할 수 있습니다. 디스플레이 및 캠페인 관리의 추가 개입 없이 Video 360 지원팀 해당 사용자만 내 데이터에 액세스할 수 있게 됩니다.
- 로그 읽기 Google 그룹
데이터에 액세스
gsutil을 사용하여 데이터 액세스
gsutil 도구는 명령줄 애플리케이션이며 프로그래밍 없이 손쉽게 Google Cloud Storage 데이터 경험해 볼 수 있습니다 예를 들어 gsutil을 커스텀 애플리케이션을 만들 수 있습니다
gsutil을 시작하려면 gsutil 문서를 참조하세요. 이전과 마찬가지로 OAuth 2를 사용하여 인증해야 하지만 gsutil 자체에서 나중에 사용할 수 있도록 사용자 인증 정보를 저장하고 저장합니다.
프로그래매틱 방식으로 데이터 액세스
Google Cloud Storage에는 다양한 프로그래밍 언어용 API가 있어
프로그래매틱 방식으로 데이터에 액세스할 수 있습니다. 아래 샘플은 간단한 kubectl 명령어를 사용하여
항목 읽기 파일 중 하나 다운로드
Google Cloud Storage에서 데이터를
저장하는 방법을 알아볼 수 있습니다 이 작업은 공개적으로
항목 읽기 파일은
버킷 gdbm-public
개 비공개
항목 읽기 파일은 파트너 및 광고주별 버킷에 저장됩니다.
자바
다음 예에서는 Google Java용 API 클라이언트 라이브러리를 사용하면 Google Cloud Cloud Storage도 손쉽게 사용할 수 있습니다. 주요 일반 Google API 클라이언트 라이브러리 외에도 또한, Cloud Storage에서 라이브러리 (Cloud Storage API용)
먼저 API와 통신할 때 사용할 사용자 인증 정보를
데이터에 액세스할 수 있는 권한을 얻을 수 있습니다. Credential
를 만들면 됩니다.
서비스 계정의 developer.gserviceaccount.com
이메일 주소를 사용하는 객체
를 ServiceAccountId
로 설정하고, 다운로드된 비공개 키 파일도 로드합니다.
서비스 계정을 만들 때 Google API 콘솔에서 확인할 수 있습니다. 이렇게 하면
API에 대한 이후 요청은 서비스 계정의 비공개 키로 서명됩니다.
NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport(); JacksonFactory JSON_FACTORY = new JacksonFactory(); ... Credential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId("...@developer.gserviceaccount.com") .setServiceAccountScopes(StorageScopes.DEVSTORAGE_READ_ONLY) .setServiceAccountPrivateKeyFromP12File(new File("...-privatekey.p12")) .build();
Credential
객체를 만든 후 이 객체를 사용하여
새로운 Storage
객체를 반환합니다.
Google Cloud Storage API:
Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, credential);
이제 새 Storage
객체가 있으므로 이 API에 대한 요청을 실행할 준비가 되었습니다.
생성합니다. 여기서는 특정 항목 bucketObjectName
를 검색하도록 요청합니다.
(bucket
버킷에서) 라이브러리는
Google Cloud Storage를 사용하고 필요한 경우 데이터를
콘솔:
Get bucketObject = storage.objects().get(bucketName, bucketObjectName); ByteArrayOutputStream output = new ByteArrayOutputStream(); bucketObject.getMediaHttpDownloader().setDirectDownloadEnabled(true); bucketObject.executeAndDownloadTo(output); System.out.println(output.toString());
bucket
및 bucketObjectName
값은 다음에 따라 달라집니다.
API에서 액세스하는 부분 태그 이름 지정에 대한 해당 섹션을
규칙을 따릅니다.
C#
다음 예에서는 .NET용 Google API 클라이언트 라이브러리를 사용하면 Google Cloud Storage에 있는 데이터에 간단하고 쉽게 액세스할 수 있습니다.
먼저 API와 통신하여 데이터에 액세스할 수 있는 권한을 얻으려면 사용할 사용자 인증 정보를 설정해야 합니다. 이 작업은 서비스 계정의 developer.gserviceaccount.com
이메일 주소를 ServiceAccountId
로 사용하고 서비스 계정을 만들 때 Google API 콘솔에서 다운로드한 비공개 키 파일도 로드하는 AssertionFlowClient
객체를 만들면 됩니다.
string keyPath = @"...-privatekey.p12"; X509Certificate2 certificate = new X509Certificate2(keyPath, "notasecret", X509KeyStorageFlags.Exportable); var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) { ServiceAccountId = "...@developer.gserviceaccount.com", Scope = StorageService.Scopes.DevstorageRead_only.GetStringValue() };
AssertionFlowClient
객체를 만든 후 이 객체를 사용하여 새 OAuth2Authenticator
객체를 인스턴스화할 수 있습니다. 이 객체는 향후 Google Cloud Storage API에 보내는 모든 요청을 위해 새 Storage
인스턴스를 인스턴스화하는 데 사용할 수 있습니다.
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); StorageService service = new StorageService(auth);
이제 새 Storage
객체가 있으므로 요청을 시작할 준비가 되었습니다.
API에 전달합니다. 여기에서는 특정 항목을 가져오도록 요청합니다.
bucket
버킷의 bucketObjectName
Google에서는 표준
HTTP 다운로드를 처리하는 .NET 클라이언트 라이브러리 클래스
Google Cloud Storage를 지원하지만, 백업이 필요할 경우
항상 올바른 Authorization
가 있는지 확인하는 리디렉션이 있습니다.
다음과 같습니다.
var results = service.Objects.Get(bucketName, bucketObjectName).Fetch(); HttpWebRequest request = createRequest(results.Media.Link, auth); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Handle redirects manually to ensure that the Authorization header is present if // your request is redirected. if (response.StatusCode == HttpStatusCode.TemporaryRedirect) { request = createRequest(response.Headers["Location"], auth); response = (HttpWebResponse)request.GetResponse(); }
그러면 HttpWebResponse
객체에서 응답 내용을 읽을 수 있습니다.
평소처럼 GetResponseStream
를 통해 전송됩니다. bucket
및
bucketObjectName
는 어떤 API에서 액세스하는지에 따라 달라집니다. 이름 지정 규칙에 대한 해당 섹션을 참조하세요.
부록: 전체 샘플
자바
/* * Copyright (c) 2013 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.bidmanager.api.samples; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.InputStreamReader; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.storage.Storage; import com.google.api.services.storage.Storage.Objects.Get; import com.google.api.services.storage.StorageScopes; /** * A simple class that demonstrates how to download a specific object from a bucket using a * service account */ public class ServiceDownload { /** * This is the HTTP Transport object used for automatically refreshing access tokens. */ static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport(); /** * This is the JSON factory used for parsing refresh token responses.Your first requirement */ static final JacksonFactory JSON_FACTORY = new JacksonFactory(); /** * The main method will attempt to download a specific named object from the gdbm-public bucket * using a service account. * * @param args Not used. */ public static void main(String[] args) { try { // Prompt the user for the details of the object to download. System.out.print("Name of object to download, e.g. entity/20130430.0.Browser.json:"); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String bucketObjectName = in.readLine(); in.close(); String bucketName = "gdbm-public"; Credential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId("...@developer.gserviceaccount.com") .setServiceAccountScopes(StorageScopes.DEVSTORAGE_READ_ONLY) .setServiceAccountPrivateKeyFromP12File( new File("...-privatekey.p12")) .build(); Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, credential); Get bucketObject = storage.objects().get(bucketName, bucketObjectName); ByteArrayOutputStream output = new ByteArrayOutputStream(); bucketObject.getMediaHttpDownloader().setDirectDownloadEnabled(true); bucketObject.executeAndDownloadTo(output); System.out.println(output.toString()); } catch (Exception e) { System.err.println("Unexpected exception caught: " + e.getMessage()); e.printStackTrace(); } } }
C#
/* * Copyright (c) 2013 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. */ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using DotNetOpenAuth.OAuth2; using Google.Apis; using Google.Apis.Requests; using Google.Apis.Authentication.OAuth2; using Google.Apis.Authentication.OAuth2.DotNetOpenAuth; using Google.Apis.Storage.v1beta1; using Google.Apis.Storage.v1beta1.Data; using Google.Apis.Util; namespace ApiSamples { /// <summary> /// A simple class that demonstrates how to download a specific object from a bucket using a /// service account /// </summary> class ServiceDownload { /// <summary> /// The main method will attempt to download a specific named object from the /// gdbm-public bucket using a service account. /// </summary> /// <param name="args">Not used.</param> public static void Main(string[] args) { // Prompt the user for the details of the object to download Console.WriteLine("Name of object to download, e.g. entity/20130430.0.Browser.json:"); string bucketObjectName = Console.ReadLine(); string bucketName = "gdbm-public"; try { string keyPath = @"...-privatekey.p12"; X509Certificate2 certificate = new X509Certificate2(keyPath, "notasecret", X509KeyStorageFlags.Exportable); var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) { ServiceAccountId = "...@developer.gserviceaccount.com", Scope = StorageService.Scopes.DevstorageRead_only.GetStringValue() }; var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); StorageService service = new StorageService(auth); var results = service.Objects.Get(bucketName, bucketObjectName).Fetch(); HttpWebRequest request = createRequest(results.Media.Link, auth); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Handle redirects manully to ensure that the Authorization header is present if // our request is redirected. if (response.StatusCode == HttpStatusCode.TemporaryRedirect) { request = createRequest(response.Headers["Location"], auth); response = (HttpWebResponse)request.GetResponse(); } Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); String data = reader.ReadToEnd(); Console.Write(data); } catch (Exception e) { Console.WriteLine("Unexpected exception caught: " + e.Message); Console.Write(e.StackTrace); } Console.ReadKey(); } /// <summary> /// Generate a HttpWebRequest for the given URL with the appropriate OAuth2 authorization /// header applied. The HttpWebRequest object returned has its AllowAutoRedirect option /// disabled to allow us to manually handle redirects. /// </summary> /// <param name="url">URL that is to be requested with this object</param> /// <param name="auth">The OAuth2Authenticator instance that contains the appropriate keys.</param> /// <returns>HttpWebRequest object ready to be used to make requests to the API</returns> private static HttpWebRequest createRequest(string url, OAuth2Authenticator<AssertionFlowClient> auth) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Headers.Add("Authorization", "Bearer " + auth.State.AccessToken); request.AllowAutoRedirect = false; return request; } } }