Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3638

Google Scripts: Urlfetchapp with Youtube API having trouble uploading videos with different owners in a shared drive folder. Processing abandoned

$
0
0

I am currently trying to automate uploading videos from a shared drive folder to Youtube using the following code from this SO post:

function upload() {  var driveurl = `https://drive.google.com/file/d/AAAAAAAAAAAAAAAAAAAAAAAAA/view?usp=share_link`  var match = driveurl.match(/([a-z0-9_-]{25,})[$/&?]/i).pop();  var url = `https://www.googleapis.com/drive/v3/files/`+match+`?alt=media`;   var title = "title";  var description = "test";  var topics = "TEST";  var blob,mp4_fileId,part,requestResource,response;  var options = {},snippet = {};  /*    You will need to create a GCP standard project and associate it with this Apps Script project-    In the new code editor click the settings cog wheel and scroll down to:    Google Cloud Platform (GCP) Project -    You may get an error:    In order to change your project, you will need to configure the OAuth consent screen. Configure your OAuth Consent details.    And if you do not have a Google Workspace account then you wont be able to set up the GCP project as "INTERNAL"    You will need to enable the Google Drive API and the YouTube API in the associated GCP project -  */  /*    This code needs the file ID of the MP4 file in your Google Drive -     To get the file ID of an MP4 video file in Google Drive, right click the MP4 in your Google Drive    and choose, "Get link"    The link will look like this:    https://drive.google.com/file/d/FILE_ID_IS_HERE/view?usp=sharing    In the URL is the file ID  */  options = {"method" : "get","headers" : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},"muteHttpExceptions":true  }  var video = UrlFetchApp.fetch(url,options); response = YouTube.Videos.insert({            snippet:{                title: title,                description: description,                tags: topics            },            status:{              privacyStatus: "public",            },       },"snippet,status",       video   );   Logger.log(JSON.stringify(response));    Logger.log(response.id)}

The code works great when I am the owner of the file. However, when I try and grab a file from another user in the same folder, the code no longer works. It tries to push a video to youtube but results in the error "Processing abandoned" visible in my youtube channel. If I copy the file and become the owner of the copy, it works fine so it is not something special with the specific video.

I thought of trying something like this The function Drive.File.get(ID) does not produce the correct object type i.e. it needs to be a blob but I cannot figure out how to get it to there. DriveApp.getFileById(match).getBlob() is my thought, but I have to wait till tomorrow to test due to hitting my upload limit for YouTube today and I'm not optimistic with the link provided.

It seems like there is some error associated with permissions, but I am not fully sure how to proceed to fix it. Any thoughts would be greatly appreciated.


Viewing all articles
Browse latest Browse all 3638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>