سؤال

Just getting started with GCS and its Java API. Adapted the Google Plus example and am trying to retrieve a bucket.

I get the error:

400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid Value",
    "reason" : "invalid"
  } ],
  "message" : "Invalid Value"
}

Here's my relevant code:

Main:

public static void main(String[] args)
{
    try
    {
        try
        {
            HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

            // service account credential (uncomment setServiceAccountUser for domain-wide delegation)
            GoogleCredential credential = new GoogleCredential.Builder()
                    .setTransport(HTTP_TRANSPORT)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
                    .setServiceAccountScopes(StorageScopes.DEVSTORAGE_READ_WRITE)
                    .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_NAME))
                    // .setServiceAccountUser("user@example.com")
                    .build();
            // set up global Storage instance
            storage = new Storage.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
            // run commands
            getBucket();
            // success!
            return;
        } catch (IOException e)
        {
            System.err.println(e.getMessage());
        }
    } catch (Throwable t)
    {
        t.printStackTrace();
    }
    System.exit(1);
}

Get bucket method:

/** Get a BUCKET??? for which we already know the ID. */
private static void getBucket() throws IOException
{
    View.header1("Retrieve a bucket by name.");
    String bucketName = "gs://gsdogs";
    Bucket bucket = storage.buckets().get(bucketName).execute();
    View.show(bucket);
}

Constants:

private static final String CLIENT_ID = "************.apps.googleusercontent.com";
private static final String KEY_FILE_NAME = "privatekey.p12";

private static final String APPLICATION_NAME = "Elf-MobileCCtv/1.0";

/** E-mail address of the service account. */
private static final String SERVICE_ACCOUNT_EMAIL = "************@developer.gserviceaccount.com";

/** Global instance of the HTTP transport. */
private static HttpTransport HTTP_TRANSPORT;

/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();

// We are using GCS not Google plus.
private static Storage storage;

Thanks in advance!

هل كانت مفيدة؟

المحلول

I had to change my bucket name from gs://gsdogs to gsdogs. Wow.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top