Skip to content

Cannot log response from videos.insert #3556

@vaughngx4

Description

@vaughngx4

I have tried using the videos.insert function asynchronously as well as with a callback function. When using with a callback function the code still executes asynchronously (which was unexpected, as without a callback it executes asynchronously as well).

I cannot seem to log the response. Below is my use of the function without the callback. In this case, the upload reaches 100%, but no response is logged. The log code isn't even reached, nothing is logged after the upload reaches 100%. With the callback function, the callback is executed before the upload completes.

async function upload(
  oauth2Client,
  videoInfo,
  thumbInfo,
  publishAt,
  title,
  description,
  notifySubscribers
) {
  let result = {};
  // this await is needed because the insert function can optionally return a promise
  // which is what we want, ignore the underline in your IDE
  try {
    const res = await youtube.videos.insert(
      {
        auth: oauth2Client,
        part: "id,snippet,status",
        notifySubscribers,
        requestBody: {
          snippet: {
            title,
            description,
          },
          status: {
            privacyStatus: "private",
            publishAt,
          },
        },
        media: {
          body: fs.createReadStream(videoInfo.path),
          mimeType: videoInfo.mime,
        },
      },
      {
        onUploadProgress: (evt) => {
          const progress = Math.round((evt.bytesRead / info.length) * 100);
          // readline.clearLine(process.stdout, 0);
          // readline.cursorTo(process.stdout, 0, null);
          // process.stdout.write(`${progress}% complete`);
          logger.log(
            "debug",
            `Uploading file ${basename(filePath)} ${progress}%`
          );
        },
      }
    );
    logger.log("sensitive", "== Upload Response ==", res.data);
    result["data"] = res.data;
  } catch (error) {
    logger.log("error", "The API is not doing API things", error);
    result["error"] = "Possibly rate limited";
  }
  return result;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions