Google Drive support

This commit is contained in:
benweet 2013-03-24 19:20:01 +00:00
parent 0e96a56e8d
commit 3f99c8cc4d

View File

@ -14,7 +14,8 @@
<script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com'; var CLIENT_ID = '241271498917-jpto9lls9fqnem1e4h6ppds9uob8rpvu.apps.googleusercontent.com';
var SCOPES = 'https://www.googleapis.com/auth/drive.install'; var SCOPES = ['https://www.googleapis.com/auth/drive.install', 'https://www.googleapis.com/auth/drive.file'];
var driveUpload = false;
/** /**
* Called when the client library is loaded to start the auth flow. * Called when the client library is loaded to start the auth flow.
@ -39,6 +40,9 @@
function handleAuthResult(authResult) { function handleAuthResult(authResult) {
if (authResult && !authResult.error) { if (authResult && !authResult.error) {
$("#drive-link").hide(); $("#drive-link").hide();
gapi.client.load('drive', 'v2', function() {
driveUpload = true;
});
} else { } else {
$("#drive-link").click(function() { $("#drive-link").click(function() {
gapi.auth.authorize({ 'client_id' : CLIENT_ID, gapi.auth.authorize({ 'client_id' : CLIENT_ID,
@ -67,6 +71,7 @@
* @param {Function} callback Function to call when the request is complete. * @param {Function} callback Function to call when the request is complete.
*/ */
function insertFile(fileData, callback) { function insertFile(fileData, callback) {
if(driveUpload) {
var request = gapi.client.request({ var request = gapi.client.request({
'path' : '/upload/drive/v2/files', 'path' : '/upload/drive/v2/files',
'method' : 'POST', 'method' : 'POST',
@ -80,6 +85,7 @@
} }
request.execute(callback); request.execute(callback);
} }
}
</script> </script>
<script type="text/javascript" <script type="text/javascript"
src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script> src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>