2

I am trying to connect to Google Cloud Storage using C# with the .NET on Google Cloud Platform

So I logged into API & Services in Google Then clicked on "Credentials" and Created a new credential. That process gave me a json file similar to the below info.

I tried to connect but keep getting the following error

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

I used the following code to connect.

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);
}

How can I correctly access Google Cloud storage bucket to get object information?

Also, how can I generate a token or username/password instead of having to log with that above json file?

Junior
  • 11,602
  • 27
  • 106
  • 212
  • 1
    Now that the post is edited, that should work if you use the right bucket name - my guess is that you've specified the wrong bucket name. That's the error you *would* get with the wrong bucket name. – Jon Skeet Jan 16 '19 at 19:35
  • I'd also strongly advise you to ask *one* question per post. For auth options, see https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth – Jon Skeet Jan 16 '19 at 19:39
  • As an example, try listing objects in the bucket `"nodatime"`. I'd expect you to get a 403 for that instead of a 404. – Jon Skeet Jan 16 '19 at 19:42
  • Can you successfully call other methods of the storage client. Like `storage.ListBuckets()'? – Jeffrey Rennie Jan 17 '19 at 19:11
  • Any updates on this? – Jon Skeet Jan 22 '19 at 08:37
  • 1
    I ended up closing the google account and use Azure instead. – Junior Jan 23 '19 at 02:52
  • That makes me sad, obviously - but if you're not going to be able to try things, and given that I suspect the problem was the wrong bucket, I'd suggest deleting this question. If you're happy to look at it again for the sake of ending up with a useful question and answer, that's a different matter of course. – Jon Skeet Jan 25 '19 at 17:52

0 Answers0