YouTube API登录

时间:2018-07-31 04:09:46

标签: youtube youtube-data-api youtube-javascript-api

简而言之,我试图允许用户自动上传到我的授权帐户,而不是使用GoogleAuth.signIn();,然后必须手动登录。反正有预定义的用户吗?

    gapi.client
        .init({
          clientId:
            "API",
          discoveryDocs: [
            "https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest"
          ],
          scope:
            "https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner"
        })
        .then(function() {
          GoogleAuth = gapi.auth2.getAuthInstance();
          GoogleAuth.signIn();
          // Listen for sign-in state changes.
          GoogleAuth.isSignedIn.listen(updateSigninStatus);

          // Handle initial sign-in state. (Determine if user is already signed in.)
          setSigninStatus();

          // Call handleAuthClick function when user clicks on "Authorize" button.

          $("#select-file-button").click(function() {
            $("#select-file").click();
          });
          $("#upload-file-button").click(function() {
            defineRequest();
          });
          $("#select-file").bind("change", function() {
            selectedFile = $("#select-file").prop("files")[0];
          });

let isAuthorized = "";
function setSigninStatus() {
  var user = GoogleAuth.currentUser.get();
  isAuthorized = user.hasGrantedScopes(
    "https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner"
  );
  // Toggle button text and displayed statement based on current auth status.
  if (isAuthorized) {
    defineRequest();
  }
}

0 个答案:

没有答案