question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google Drive API method files.get with alt: media parameter returning all special characters

See original GitHub issue

I am trying to get a specific image file’s metadata so I can get the download url to input into a batch update request to create an image to input into a Google Slides presentation. I am using the files.get call which should return a lot of metadata. If I do the ‘Try it Out’ here it returns the correct data, however when I input that same fileId into my code, it only returns the name, id, kind and mimeType. I suspected this was because I need to add alt: media, but when I do that I get a return with all special characters.

Here is my code snippet:

authClient.refreshAccessToken(function(err, tokens) {
  if (err) {
    console.log(err);
    return;
  }
  drive.files.get({
    fileId: fileId,
    auth: authClient, 
    alt: 'media'
  }, function(err, res) {
    if (err) {
      return console.log(err);
    }
    else {
      return console.log(res);
    }
  });
});

The return with alt: ‘media’ is a long list of special characters like this: A�c|��*����u�f����J.

This is the return without alt: ‘media’:

{ 
  kind: 'drive#file',
  id: 'Photo ID',
  name: 'Photo Name',
  mimeType: 'image/jpeg' 
}

EDIT: The below question has been partially solved. see below comment.

Also, I am wondering what the image url in the request body of the createImage object for the batchUpdate method should be. Here it just says to use the image url and when I’ve tried adding the self link, web content link, download url, embed link, etc. and I keep getting this error:

{
  "error": {
    "code": 400,
    "message": "Invalid requests[0].createImage: There was a problem retrieving the specified image.",
    "status": "INVALID_ARGUMENT"
  }
}

Any advice would be greatly appreciated!

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
erickoledadevrelcommented, May 29, 2019

Yes, there is a tension here since the URL needs to be accessible for the Slides API backend to access it, which either means it’s publicly accessible for some period of time or the security token is captured in the URL and available in the presentation’s metadata.

1reaction
dallashugginscommented, Apr 16, 2018

Hey - I went another route when I was figuring this out, sorry I didn’t close this. When I wasn’t able to get the chart image address, I instead went the alternative route of using Google Sheets to create a new tab in a spreadsheet, add data and then create the chart to then send to the presentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alt=Media not downloading file when access token is provided ...
First, we're making changes to authorization for the Google Drive API. If you authorize download requests to the Drive API using the access ......
Read more >
Files: get | Google Drive
Downloading content with alt=media only works if the file is stored in Drive. To download Google Docs, Sheets, and Slides use files.
Read more >
Speech-to-Text request construction - Google Cloud
This document is a guide to the basics of using Speech-to-Text. This conceptual guide covers the types of requests you can make to...
Read more >
Programmatically Uploading Images, Videos, and Other Files
The Cloudinary upload method performs an authenticated upload API call over ... For some special considerations for video and raw files, ...
Read more >
Drive.Files.get('File ID',{alt:'media'}) doesn't return file content
“ eht esu ro ,retemarap kniLtnetnoCbew eht gnisu yb tnetnoc yranib eht teg nac uoY Export method to retrieve the text of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found