0
var sourceFolderId = "15Kux2yyL_OWoZBwnYPbJtyrlp1zQjY3T";
var folder = DriveApp.getFolderById(sourceFolderId);
var token = ScriptApp.getOAuthToken()
var imageUrl = folder.getFilesByName(uid).next().getDownloadUrl() + "&access_token=" + 
ScriptApp.getOAuthToken();
var slide = Slides.Presentations.get(newTargetDocId).slides[0]

Logger.log(token) 
Logger.log(imageUrl)

I have been using the above code to get an image from google drive and using batchupdate put it into google slides, however the auth token no longer allows a download, do i need to refresh it somehow?

The url goes to the correct image and the image is the correct file format but the code returns API call to slides.presentations.batchUpdate failed with error: Invalid requests[1].createImage: The provided image is in an unsupported format. (line 243, file "Code").

I know the image is ok as i have already used it. I know the url is correct as it takes me to the image if i cut the authtoken off. The authtoken on the end no longer allows me to download the file on another browser.

New code based on comment about Drive changes

var sourceFolderId = "15Ku...............zQjY3T";
var folder = DriveApp.getFolderById(sourceFolderId);

var file = folder.getFilesByName(uid).next()

file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
var imageUrl = "https://drive.google.com/uc?export=download&id=" + file.getId();

But now i get an invalid argument error on file.setSharing line

Rafa Guillermo
  • 14,474
  • 3
  • 18
  • 54
  • Is this information useful for your situation? https://stackoverflow.com/q/60076883 – Tanaike Feb 06 '20 at 11:56
  • The way authentication works for the `files.get()` enpoint of Drive changed at the beginning of 2020. I think Tanaike's comment (as always) will be the solution you are looking for, can you confirm this? @GeorgeCliffe – Rafa Guillermo Feb 06 '20 at 12:02
  • I have added to the question the new code based on this but now i have an invalid argument on the file.setSharing line – George Cliffe Feb 06 '20 at 22:52
  • I believe this is something to do with permissions set in Gsuite security? "ANYONE Enum Anyone on the Internet can find and access. No sign-in required. Domain administrators can prohibit this setting for users of a G Suite domain. If the setting is disabled, passing this value to File.setSharing(accessType, permissionType) throws an exception." – George Cliffe Feb 07 '20 at 00:22
  • @Tanaike, I have read your other post and followed it properly this time but i am still getting an error, do you know if im on the right track for enabling a permission to be set to public within Gsuite? – George Cliffe Feb 07 '20 at 08:45
  • 1
    Issue now resolved thanks – George Cliffe Feb 07 '20 at 17:53
  • Thank you for replying. I'm glad your issue was resolved. When your issue was resolved, can you post is as an answer? By this, it will help users who have the same issue. – Tanaike Feb 07 '20 at 23:22

1 Answers1

1
  var sourceFolderId = "15Ku...............zQjY3T";
  var folder = DriveApp.getFolderById(sourceFolderId);

  var file = folder.getFilesByName(uid).next()

  file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
  var imageUrl = "https://drive.google.com/uc?export=download&id=" + file.getId();

General file permissions will need to be altered to allow this to run with Gsuite admin pages