So I downloaded .NET client for Cloud Storage from Nuget (Google.Apis.Storage.v1, version=1.8.1.10), created a project using Developer Console, generated API key, enabled billing, created a bucket.
But when I'm trying to list all objects in a bucket, I'm getting this error (login required). Any ideas why that may be? Cloud Storage and its JSON API are enabled in console.
Here's full code from my sample app: https://gist.github.com/chester89/5d6a62633abab3969c32
An API key is a simple marker that says "this call is associated with this project." It is useful for managing quota, but it is not a secret and does not authenticate the caller as any particular user. Your bucket presumably is not browsable by anonymous callers, and your call is made anonymously.
You could fix this by granting anonymous users read access to your bucket, but a better idea would be to authenticate your requests. You have several options on how to do this, depending on whether you want to make the calls with your own personal credentials or whether you want to use a service account associated with your application. Full instructions are documented here: https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth
Guessing that you want to authenticate as yourself and that you're writing an application that will run on your desktop, here's an example:
UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { BooksService.Scope.Books },
"user", CancellationToken.None, new FileDataStore("Books.ListMyLibrary"));
}
// Create the service.
var service = new BooksService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Books API Sample",
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With