0
votes

I've followed the guide on how to use GCS on their site:

but
Once Unauthorized used

I then get

Failed to load resource: the server responded with a status of 400 ()

{"error":{"errors":[{"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"}],"code":400,"message":"Bad Request"}}

  1. Here is my step
  2. create the javascript page from this authSample.html
  3. change clientId to google console page

OAuth 2.0 user ID:??????????????????????.apps.googleusercontent.com

  1. change apiKey to google console page

OAuth 2.0 user api key

  1. run the authSample.html

What am I doing wrong?

2
Based on the "keyInvalid" message, I'm wondering if you have perhaps put in the wrong API key? Double check the key. - Brandon Yarbrough
Are you sure you have entered the domain you are serving the javascript from in the developers console? Make sure to include it as a valid REST domain and also as a redirect url. - Danielo515
yes i set then domain and domain/authSample.html - Leo JI
Which APIs are you trying to use ? Whether you need API key or a Service account key or OAuth client ID depends on what you intend to use, please provide details on what you are trying to accomplish and also the code that you have currently - Raghvendra Kumar

2 Answers

0
votes

So this bug occurs because of an incorrect way of loading and authorising API's.

The correct way is to first use

  1. gapi to load client (no auth required)
  2. next load, the "storage","v1"
  3. finally Authorise

    gapi.load('client', () => {
    
    gapi.client.load('storage', 'v1', authResult =>{
    
    gapi.auth.authorize({
          client_id: CLIENT_ID,
          scope: SCOPES,
          immediate: false
        },authResult=>{
    
          if (authResult && !authResult.error) {
            var request = gapi.client.storage.buckets.list({
              'project': PROJECT_ID
            });
            request.execute(function(resp) {
              console.log(resp)
            });
    
        } else {
           alert("Un-Authorised")
        }
    
    
        });
    
    });
    
    });
    
-1
votes

The supported client libraries are limited to a number of languages only. If you wish to build a solution around those, you can refer these here

https://cloud.google.com/storage/docs/json_api/v1/libraries#api-client-libraries