Skip to content Skip to sidebar Skip to footer

Keep Receiving Login Required Error When Trying To Upload A File To Google Drive

I am writing a chrome extension that will intercept certain downloads (currently .doc and .docx files) and instead take those files and automatically upload them to your Google dri

Solution 1:

This might help others stumbling upon this question. If you did authorise using JWT, make sure to include auth: <your jwtClient> in your API call, like:

First, get the token:

// Configure JWT auth clientvar privatekey = require("./<secret>.json")
var jwtClient = new google.auth.JWT(
  privatekey.client_email,
  null,
  privatekey.private_key,
  ['https://www.googleapis.com/auth/drive']
);

// Authenticate request
jwtClient.authorize(function (err, tokens) {
  if (err) {
    return;
  } else {
    console.log("Google autorization complete");
  }
});

Then, call the API (but don't forget the auth:jwtClient part)

drive.files.create({
    auth: jwtClient,
    resource: {<fileMetadata>},
    fields: 'id'
  }, function (err, file) {
    if (err) {
      // Handle error
    } else {
      // Success is much harder to handle
    }
});

Solution 2:

Google Drive API (and other Google products as well) uses oAuth2.0 for its authorization protocol. All requests that will be made are to be authorized.

The detailed steps in authorizing your application to use the Drive API can be found in the documentation.

  1. When you create your application, you register it using the Google Developers Console. Google then provides information you'll need later, such as a client ID and a client secret.
  2. Activate the Drive API in the Google Developers Console. (If the API isn't listed in the Developers Console, then skip this step.)
  3. When your application needs access to user data, it asks Google for a particular scope of access.
  4. Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
  5. If the user approves, then Google gives your application a short-lived access token.
  6. Your application requests user data, attaching the access token to the request.
  7. If Google determines that your request and the token are valid, it returns the requested data.

You can use https://www.googleapis.com/auth/drive if you want full access to the user's files, or a specific one listed on the page as well.

Solution 3:

if you're using swift: add the next module at the beginning of viewcontroller "import GTMSessionFetcher"

I can't use fetcher authorizer without this library, it was created when your install your pod file

Post a Comment for "Keep Receiving Login Required Error When Trying To Upload A File To Google Drive"