如何从(使用 PHP 的 Google 云端硬盘)代码中删除身份验证弹出窗口。
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 驱动器。这段代码实际上工作正常,这是在身份验证后建立与我的 Google 驱动器的连接。出现弹出窗口对用户进行身份验证,然后用户单击允许,然后确认身份验证。并且用户将被允许访问(读取)来自 google 驱动器的文件。我想删除此身份验证。并在代码中手动输入我的电子邮件地址和密码。我不知道如何改变在哪里改变。以及在哪里放置我的密码和电子邮件地址以避免身份验证。
我只想删除身份验证我的个人目的。不一般。
正如您在 link 中看到的那样,您发布了 Google Identity Platform
Important: ClientLogin has been officially deprecated as of April 20,
2012 and is no longer available as per our deprecation policy. We
encourage you to migrate to OAuth 2.0 as soon as possible.
ClientLogin 是已弃用的身份验证协议,将于 2015 年 4 月 20 日 关闭。届时,将不再响应 ClientLogin 请求。如果您有使用 ClientLogin 的现有应用程序,我们鼓励您迁移到 OAuth。此库中的 ClientLogin 支持将在下一个主要版本中删除。
无法使用登录名和密码以编程方式对 Google API 进行身份验证。您需要使用您正在执行的 OAuth2 或使用服务帐户访问 Google 驱动器上的文件。
听起来您只想访问自己的数据我建议您查看服务帐户。 service-account.php
<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 驱动器。这段代码实际上工作正常,这是在身份验证后建立与我的 Google 驱动器的连接。出现弹出窗口对用户进行身份验证,然后用户单击允许,然后确认身份验证。并且用户将被允许访问(读取)来自 google 驱动器的文件。我想删除此身份验证。并在代码中手动输入我的电子邮件地址和密码。我不知道如何改变在哪里改变。以及在哪里放置我的密码和电子邮件地址以避免身份验证。 我只想删除身份验证我的个人目的。不一般。
正如您在 link 中看到的那样,您发布了 Google Identity Platform
Important: ClientLogin has been officially deprecated as of April 20, 2012 and is no longer available as per our deprecation policy. We encourage you to migrate to OAuth 2.0 as soon as possible.
ClientLogin 是已弃用的身份验证协议,将于 2015 年 4 月 20 日 关闭。届时,将不再响应 ClientLogin 请求。如果您有使用 ClientLogin 的现有应用程序,我们鼓励您迁移到 OAuth。此库中的 ClientLogin 支持将在下一个主要版本中删除。
无法使用登录名和密码以编程方式对 Google API 进行身份验证。您需要使用您正在执行的 OAuth2 或使用服务帐户访问 Google 驱动器上的文件。
听起来您只想访问自己的数据我建议您查看服务帐户。 service-account.php