如何删除身份验证弹出(GoogleDrive使用PHP)代码


How to remove authentication popup from (GoogleDrive using PHP) code.

      <head>    
    <script type="text/javascript">    
      // Your Client ID can be retrieved from your project in the Google    
      // Developer Console, https://console.developers.google.com    
      var CLIENT_ID = '581911360711-3tu7tqe9jo3irbp6oqkkhqivjb5qgcdq.apps.googleusercontent.com';    
  var SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly'];
  /**
   * Check if current user has authorized this application.
   */
  function checkAuth() {
    gapi.auth.authorize(
      {
        'client_id': CLIENT_ID,
        'scope': SCOPES,
        'immediate': true
      }, handleAuthResult);
  }
  /**
   * Handle response from authorization server.
   *
   * @param {Object} authResult Authorization result.
   */
  function handleAuthResult(authResult) {
    var authorizeDiv = document.getElementById('authorize-div');
    if (authResult && !authResult.error) {
      // Hide auth UI, then load client library.
      authorizeDiv.style.display = 'none';
      loadDriveApi();
    } else {
      // Show auth UI, allowing the user to initiate authorization by
      // clicking authorize button.
      authorizeDiv.style.display = 'inline';
    }
  }
  /**
   * Initiate auth flow in response to user clicking authorize button.
   *
   * @param {Event} event Button click event.
   */
  function handleAuthClick(event) {
    gapi.auth.authorize(
      {client_id: CLIENT_ID, scope: SCOPES, immediate: false},
      handleAuthResult);
    return false;
  }
  /**
   * Load Drive API client library.
   */
  function loadDriveApi() {
    gapi.client.load('drive', 'v2', listFiles);
  }
  /**
   * Print files.
   */
  function listFiles() {
    var request = gapi.client.drive.files.list({
        'maxResults': 15
      });
      request.execute(function(resp) {
        appendPre('Files:');
        var files = resp.items;
        if (files && files.length > 0) {
          for (var i = 0; i < files.length; i++) {
            var file = files[i];
            appendPre(file.title + ' (' + file.id + ')');
          }
        } else {
          appendPre('No files found.');
        }
      });
  }
  /**
   * Append a pre element to the body containing the given message
   * as its text node.
   *
   * @param {string} message Text to be placed in pre element.
   */
  function appendPre(message) {
    var pre = document.getElementById('output');
    var textContent = document.createTextNode(message + ''n');
    pre.appendChild(textContent);
  }
</script>
<script src="https://apis.google.com/js/client.js?onload=checkAuth">
</script>

</head>
  <body>
    <div id="authorize-div" style="display: none">
      <span>Authorize access to Drive API</span>
      <!--Button for the user to click to initiate auth sequence -->
      <button id="authorize-button" onclick="handleAuthClick(event)">
        Authorize
      </button>
    </div>
    <pre id="output"></pre>
  </body>

上面的代码是关于,通过PHP连接到谷歌驱动器。这段代码实际上工作得很好,这是建立连接到我的身份验证后的谷歌驱动器。弹出窗口显示用户身份验证,然后用户单击允许,然后身份验证确认。用户将被允许从谷歌驱动器访问(读取)文件。我想删除这个身份验证。并手动将我的电子邮件地址和密码放入代码中。我不知道该如何改变,该在哪里改变。我的密码和电子邮件地址应该放在哪里,以避免身份验证。我想取消认证只是出于个人目的。不是一般的。

从你发布的Google Identity Platform

链接中可以看到

重要:ClientLogin已于4月20日正式弃用,2012年,根据我们的折旧政策不再可用。我们建议您尽快迁移到OAuth 2.0。

ClientLogin是一个已弃用的身份验证协议,在2015年4月20日上被拒绝。届时,将不再应答ClientLogin请求。如果您有使用ClientLogin的现有应用程序,我们建议您迁移到OAuth。这个库中的ClientLogin支持将在下一个主要版本中删除。

不可能通过编程方式使用Login和Password对Google API进行身份验证。你需要使用你正在使用的OAuth2或使用服务帐户访问谷歌驱动器上的文件。

听起来你只想访问你自己的数据,我建议你考虑一个服务帐户。service-account.php