Reputation: 327
<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>
Code above is about to , connect to google drive through PHP. This code is actually working fine, this is establishing connection to my Google drive after authentication . Popup appears to authenticate the user , then user click on allow, then authentication confirmed. and user will be allowed to access(read) files from google drive. I want to remove this authentication . and put manually my EmailAddress and Password in the code. i dont know how to change where to change. and where to put my password and emailaddress to avoid authentication . i want to remove authentication only my personal purpose. not general .
Upvotes: 1
Views: 722
Reputation: 117301
As you can see in the link you posted 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 is a deprecated authentication protocol and is being turned down on April 20, 2015. At that time, ClientLogin requests will no longer be answered. If you have existing applications that use ClientLogin, we encourage you to migrate to OAuth. The ClientLogin support in this library will be removed in the next major release.
It is not possible to programmatically authenticate to a Google API using Login and Password. You need to either use OAuth2 which you are doing or use a service account to access files on Google drive.
It sounds like you only want to access your own data I suggest you look into a service account. service-account.php
Upvotes: 2