如何使用C#连接到Google Cloud Storage?

时间:2019-01-16 17:59:49

标签: c# google-cloud-platform google-cloud-storage

我正在尝试使用C#.NET on Google Cloud Platform

连接到Google Cloud Storage

因此,我在Google中登录了API & Services,然后单击“凭据”并创建了一个新凭据。该过程为我提供了一个类似于以下信息的json文件。

我尝试连接,但始终收到以下错误

GoogleApiException: Google.Apis.Requests.RequestError
Not Found [404]
Errors [
    Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
]

我使用以下代码进行连接。

string json = "{
  \"type\": \"service_account\",
  \"project_id\": \"proud-will-228718\",
  \"private_key_id\": \"fdgdfgdfgdfgdfgdg\",
  \"private_key\": \"private key\",
  \"client_email\": \"email address\",
  \"client_id\": \"clientid\",
  \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",
  \"token_uri\": \"https://oauth2.googleapis.com/token\",
  \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",
  \"client_x509_cert_url\": \"cert\"
}";

GoogleCredential credential = GoogleCredential.FromJson(json);
var storage = StorageClient.Create(credential);
var options = new ListObjectsOptions() { Delimiter = delimiter };
foreach (var storageObject in storage.ListObjects(
    bucketName, prefix, options))
{
    Console.WriteLine(storageObject.Name);
}

如何正确访问Google Cloud存储桶以获取对象信息?

此外,如何生成令牌或用户名/密码,而不必使用上面的json文件登录?

0 个答案:

没有答案