Search code examples
google-apps-scriptpermissionsyoutubeyoutube-data-apiscopes

Cannot update my own comment using YouTube Data API and Google Apps Script


I'm working with Google Apps Script and Google Sheets for update the comments I made on certain videos.

While using the code I post bellow, I got this message:

The comment could not be updated due to insufficient permissions. The request might not be properly authorized.

Despite the fact I'm updating my own comment from my Google/YouTube account and I've set the authorization scope https://www.googleapis.com/auth/youtube.force-ssl - as indicated on the documentation.

I also check this question - which is similar to mine - but, mine is oriented to Google Sheets.

This is the code I'm using:

// Text from the comment_ID "": 
/* The Magic Cylinder animation is real or am edit?
 * Honest question, I don't play MD, just looking video edits xD 
 */

/** 
 * Comment (reply) to send as body request. 
 * Sample body  - took from YouTube Data API documentation: 
*/
var myCommentBodyRequest = {
  "id": "UgyBzIHN1fFHveTCRb14AaABAg", // <= Id of my comment.
  "snippet": {
    "textOriginal": "The Magic Cylinder animation is real or an edit?" // <= Updated comment text.
  }
};

// Update the comment: 
/** Response of the updated comment:  */
var commentCreatedResponse = YouTube.Comments.update(myCommentBodyRequest, "snippet");

// Testing results: 
Logger.log(commentCreatedResponse);

// Update the cell with the new text:  
sheet.getRange("E" + sheet.getCurrentCell().getRow()).setValue(commentText);

// Show alert: 
ui.alert("The comment was updated successfully.");

I already have the "appsscript.json" file updated as follows:

{
  "timeZone": "America/Bogota",
  "dependencies": {
    "enabledAdvancedServices": [
      {
        "userSymbol": "YouTube",
        "version": "v3",
        "serviceId": "youtube"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets.currentonly",
    "https://www.googleapis.com/auth/spreadsheets",
    "https://www.googleapis.com/auth/script.container.ui",
    "https://www.googleapis.com/auth/youtube.force-ssl"
  ]
}

Normally, when a scope is added and/or Google Scripts shows an alert indication that Google Sheets requires permission, I accept the permission, but, I keep getting this message.

I think this error I'm getting is because the script must be authorized/approved by Google, but, I haven't found any evidence

Is there any missing steps/configurations to update the comment using Google Sheets?

Added tickets on Issue Tracker:


Solution

  • The issue was solved internally by the YouTube team.

    Link of the response to the ticket:

    Verified by el...@google.com.

    Hello, This issue is already fixed. Please let us know or open this ticket, if you still encounter this issue. Thank you.

    Since then, I tried to replicate the issue and even to this day (14/12/2022), I can update my own comments via YouTube Data API and Google Apps Script.