morrows_end
morrows_end

Reputation: 337

Google drive API for upload not working at all

I've read a lot of other people with half of this problem, and tried their solutions, but I can't get anywhere with it.

I first ran the example tutorials from google here: https://campus.codeschool.com/courses/discover-drive/

Then I ran the example code from here: https://developers.google.com/picker/docs/index

Running those codes with my API and client keys (I've even created new keys, tried using only the part before the .apps.googleusercontent.com for the client key as I've seen in some other example code, etc.) and I get the same result.

The page loads and asks for permission to access google drive for an account As soon as I give it permission it reverts to the following error:

Jconsole Error

I have a useless window error that says:

There was an error! The API developer key is invalid.

Now Other people have said the error was normal, and that their code still worked. Mine on the other hand does not work, AND it gives me that error.

<script>
  var clientId = '249642562982-8ss843cvik6r1rrm94i1kt5cf4jf201c.apps.googleusercontent.com';
  var developerKey = 'AIzaSyBeDBmIqzCYCNvrpSwXcLz6ido_qGZL6sg';
  var accessToken;
  function onApiLoad() {
    gapi.load('auth', authenticateWithGoogle);
    gapi.load('picker');
  }
  function authenticateWithGoogle() {
    window.gapi.auth.authorize({
      'client_id': clientId,
      'scope': ['https://www.googleapis.com/auth/drive']
    }, handleAuthentication);
  }
  function handleAuthentication(result) {
    if(result && !result.error) {
      accessToken = result.access_token;
      setupPicker();
    }
  }
  function setupPicker() {
    var picker = new google.picker.PickerBuilder()
      .setOAuthToken(accessToken)
      .setDeveloperKey(developerKey)
      .addView(new google.picker.DocsUploadView())
      .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
      .setCallback(myCallback)
      .build();
    picker.setVisible(true);
  }
  function myCallback(data) {
    if (data.action == google.picker.Action.PICKED) {
      alert(data.docs[0].name);
    } else if (data.action == google.picker.Action.CANCEL) {
      alert('goodbye');
    }
  }
</script>
<script src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>

Here are my keys

This is driving me nuts! It feels like I've tried everything and nothing is working. Why would google spend time to create a tutorial site, with full-on video lessons that check your code's validity if the flippin' resulting code doesn't work!? Take down the videos and example code if it is broken! I've wasted all day on this.

Can anyone help me figure out what's going on here?

References:

How to upload file on google drive from my website?

Using Google Drive in an iFrame doesn't work

Google Drive Picker - Developer Key is Invalid Error

Google Drive API OAuth 2.0; Error: origin_mismatch

Upvotes: 2

Views: 2415

Answers (1)

rpm
rpm

Reputation: 583

I would recommend to use this example. I have also tested this example, it is working for me. You can edit the scope according to your requirements.

Upvotes: 1

Related Questions