Google Görüntülü Reklam Ağı ve Video 360, Varlık Okuma Dosyalarını otomatik olarak depolar Google Cloud Storage'da. Bu dosyalara yalnızca şu kullanıcılar erişebilir: erişim izni verilen hesaplardır.
Proje oluşturma
Aşağıdaki gibi bir proje oluşturun ve yapılandırın:
- Google API Konsolu Etkin API'ler sayfasına gidin.
Google'da henüz oturum açmadıysanız oturum açmanız istenir.
- Proje açılır menüsünden mevcut bir projeyi seçin veya yeni bir proje oluşturun.
- Birden fazla mevcut projeniz varsa projeyi seçtiğinizden emin olun Google Cloud Storage'ı etkinleştirmek istediğiniz depolama alanı ve ardından Devam'ı tıklayın.
- Projeniz yoksa Yeni proje oluştur'u seçin, bir proje adı girin ve ardından Oluştur'u seçin.
Not: Bazı kaynak tanımlayıcılarının projenizin ömrü boyunca saklanabilir. Bu nedenle, hassas bilgileri kaynakta saklamaktan kaçının tanımlayıcılar.
- Etkin API'ler listesinde Google Cloud Storage bileşeninin listelendiğinden emin olun.
Listede yoksa Google APIs (Google API'leri) sekmesini tıklayın ve Google Cloud'u bulup seçin.
Storage bileşenini, ardından da Enable API'yi (API'yi Etkinleştir) tıklayın.
Çoğu projede Google Cloud Storage bileşeninin zaten etkinleştirilmiş olduğunu unutmayın. Planınız: Google Cloud Storage'a JSON API'yi kullanarak erişmeyi seçtikten sonra, Google Cloud Storage JSON API'nin de etkinleştirildiğini doğrulamanız gerekir.
- Proje için faturalandırmayı etkinleştirin.
Google Cloud Storage'ı kullanabilmek için öncelikle ve bir proje planı oluşturun. Faturalandırmanın etkinleştirilmesi, ücretlendirileceğiniz anlamına gelir. Daha fazla bilgi edinmek için Fiyatlandırma'ya göz atın.
- Yine bulut depolama projesinde, sol üst köşedeki galeri menüsünü tıklayın ve Faturalandırma'yı seçin.
- Henüz faturalandırma hesabınız yoksa aşağıdaki talimatları uygulayarak yeni bir faturalandırma hesabı oluşturun.
- Mevcut bir faturalandırma hesabınız varsa seçin ve ardından Hesap belirle'yi seçin.
Google API Konsolu'nda aynı projede kalın ve bir sonraki bölüme geçin.
Cloud Storage erişimini ayarlayın
Gerekli projenin Google API Konsolu'nda, sol üst köşeden API'ler ve Hizmetler'i ve ardından Kimlik bilgileri'ni tıklayın. Kimlik bilgileri sayfasında Hizmet hesabı anahtarları'nı bulun.
Hizmet hesabı anahtarı e-posta adresini bulun:
- Hizmet Hesaplarını Yönet bağlantısını (Hizmet hesabı anahtarları bölümünün sağında) seçin.
- E-posta adresi, görüntülenen İzinler sayfasında görüntülenebilir.
Hizmet hesabı anahtarı yoksa yeni bir Hizmet hesabı oluşturun:
- Kimlik bilgileri oluştur açılır menüsünü, ardından Hizmet hesabı anahtarı'nı seçin.
- Hizmet hesabı açılır menüsünden Yeni hizmet hesabı'nı seçin.
- Hizmet hesabı için bir Ad girin. Hizmet hesabı kimliği otomatik olarak projenin adı ve izni kullanılarak oluşturulur.
- Hizmet hesabı kimliği
gserviceaccount.com
e-posta adresini not edin. Oluştur'u seçmenizin ardından Kimlik Bilgileri sayfasında gösterilmez. - Anahtar türü bölümünde JSON'yi seçin.
- Oluştur'u tıklayın. Hesabın ortak/özel anahtar çiftinin bulunduğu JSON dosyası İndirilenler klasörünüze dokunun. Bu anahtar, uygulamanızın kimliğini API'ye doğrulamak için kullanılır ve gönderdiği tüm istekleri imzalamalıdır. Oluşturulan JSON dosyasını güvenli bir yerde saklayın, uygulamanızın erişebileceği bir yerde bulunmalıdır.
Display &Video 360'a Video 360 Destek Ekibi, Varlık Okuma dosyalarının etkinleştirilmesini talep edebilir ve/veya Google Bid Manager API'sini kullanabilirsiniz.
Destek Ekibi erişimi onayladıktan sonra özel bir Google Grubu oluşturun. (veya gruplar için) tıklayın ve Display & & Video 360'ta aşağıdaki alanları güncelleyin Video 360 iş ortağı ayrıntıları (yalnızca kullanıcıların İş ortağı seviyesinde erişimi olan kullanıcılar bu güncellemeleri yapabilir):
- Günlük Okuma Google Grubu
Salt okunur grup yalnızca dosya okuma ve depolama alanı gruplarının içeriğini listeleme izinlerine sahiptir. - Günlük Yönetimi Google Grubu
Yönetim grubu, salt okunur grubun tüm izinlerine sahiptir ancak bunların EKL'lerini kontrol edin. Yönetim grubunun bile izne sahip olmadığını unutmayın. değiştirmelerine izin verilmez. Ayrıca, dosya oluşturma, değiştirme veya silme iznine de sahip değillerdir.
Google Grubu eklendikten sonra gerektiği şekilde Google Grubunuza kullanıcı ekleyebilir ve gruptan kullanıcı çıkarabilirsiniz. veya Video 360 destek ekibi; yalnızca bu kullanıcılar Grubunuzdaki kullanıcılar verilerinize erişebilecek.
- Günlük Okuma Google Grubu
Verilerinize erişme
gsutil'i kullanarak verilere erişme
gsutil aracı, Programlamaya gerek kalmadan Google Cloud Storage verilerini kolayca kullanabilirsiniz sahip olacaksınız. Örneğin, ve özel uygulamalar oluşturmaktır.
gsutil'i kullanmaya başlamak için gsutil belgelerini okuyun. Daha önce olduğu gibi OAuth 2 kullanarak da kimlik doğrulaması yapmanız gerekir ancak gsutil'in kendisi sizden kimlik bilgilerini ilk kez kullanırken ve daha sonra kullanmak üzere saklar.
Verilere programatik olarak erişme
Google Cloud Storage, birçok programlama diline yönelik API'lerle uyumludur.
hızlı ve kolay bir şekilde erişmenizi sağlar. Aşağıdaki örnekte, basit bir
Varlık Okuma Dosyalarından birini indirerek
Google Cloud Storage. Unutmayın ki bu kişiler
Varlık Okuma Dosyaları
gdbm-public
paket; gizli
Varlık Okuma Dosyaları, İş Ortağına ve Reklamverene özel gruplarda depolanır.
Java
Aşağıdaki örnekte Google Google'da muhafaza edilen verilere erişimi sağlayan API'ler İçin Java İstemci Kitaplığı Cloud Storage'ı kullanabilirsiniz. Ana genel Google API'leri İstemci Kitaplığı'na ek olarak, ayrı ayrı indirmelisiniz kitaplık (Cloud Storage API için).
Öncelikle API ile iletişim kurarken kullanılacak kimlik bilgilerini ayarlamanız gerekir:
verilerinize erişme yetkisi alabilirsiniz. Bu işlem, bir Credential
oluşturarak gerçekleştirilir
Hizmet Hesabının developer.gserviceaccount.com
e-posta adresini kullanan nesne
ServiceAccountId
olarak tanımlar ve ayrıca, indirdiğiniz özel anahtar dosyasını da
Google API Konsolu'ndan güncelleyebilirsiniz. Böylece tüm proje görevlerinin
API'ye yapılacak gelecekteki istekler Hizmet Hesabının özel anahtarıyla imzalanır:
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
nesnesini oluşturduktan sonra, bunu bir örnek oluşturmak için kullanabilirsiniz
gelecekteki tüm isteklerde kullanabileceğiniz yeni Storage
nesnesi
Google Cloud Storage API'si:
Storage storage = new Storage(HTTP_TRANSPORT, JSON_FACTORY, credential);
Artık yeni bir Storage
nesneniz olduğuna göre,
API. Burada, bucketObjectName
adlı belirli bir öğeyi almak için istekte bulunuyorsunuz
bucket
paketinden. Kitaplık, dosyanın HTTP üzerinden
Google Cloud Storage'a aktarabilir ve sonra da içeriği hemen
konsol:
Get bucketObject = storage.objects().get(bucketName, bucketObjectName); ByteArrayOutputStream output = new ByteArrayOutputStream(); bucketObject.getMediaHttpDownloader().setDirectDownloadEnabled(true); bucketObject.executeAndDownloadTo(output); System.out.println(output.toString());
bucket
ve bucketObjectName
için değerleriniz bağlı olarak değişiklik gösterir
API'nin hangi bölümüne eriştiğiniz; ve adlandırma ile ilgili bölüme bakın.
belirler.
C#
Aşağıdaki örnekte .NET için Google API'leri İstemci Kitaplığı. Bu araç, Google Cloud Storage'da tutulan verilere erişimi basit ve kolay hale getirir.
Öncelikle, verilerinize erişim yetkisi almak için API ile iletişim kurarken kullanılacak kimlik bilgilerini ayarlamanız gerekir. Bu işlem, ServiceAccountId
olarak Hizmet Hesabının developer.gserviceaccount.com
e-posta adresini kullanan ve ayrıca Hizmet Hesabı oluşturulurken Google API Konsolu'ndan indirilen özel anahtar dosyasını yükleyen bir AssertionFlowClient
nesnesi oluşturularak gerçekleştirilir.
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
nesnesini oluşturduktan sonra, bu nesneyi Google Cloud Storage API'sine yapılacak tüm istekler için yeni bir Storage
örneği oluşturmak amacıyla kullanabileceğiniz yeni bir OAuth2Authenticator
nesnesi örneklendirmek için kullanabilirsiniz:
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); StorageService service = new StorageService(auth);
Artık yeni bir Storage
nesneniz olduğuna göre, istekte bulunmaya başlayabilirsiniz
bağlantı kurmalısınız. Burada, belirli bir öğeyi almak için istekte bulunuyorsunuz.
bucketObjectName
, bucket
paketinden. Standart
Şuradan HTTP indirmesini gerçekleştirecek .NET istemci kitaplığı sınıfları
Google Cloud Storage gibidir ancak
Her zaman doğru Authorization
olduğundan emin olmak için bir yönlendirme vardır
istekte bulunan başlık:
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(); }
Böylece yanıtın içeriği HttpWebResponse
nesnesinden okunabilir
her zamanki gibi GetResponseStream
üzerinden. bucket
ve için değerleriniz
bucketObjectName
, API'nin hangi bölümüne eriştiğinize bağlı olarak değişiklik gösterir; adlandırma kuralları hakkındaki ilgili bölüme bakın.
Ek: Tam Örnekler
Java
/* * 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; } } }