Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot log response from videos.insert #3556

Open
vaughngx4 opened this issue Sep 11, 2024 · 0 comments
Open

Cannot log response from videos.insert #3556

vaughngx4 opened this issue Sep 11, 2024 · 0 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@vaughngx4
Copy link

vaughngx4 commented Sep 11, 2024

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;
}
@vaughngx4 vaughngx4 added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

1 participant