user2732609
user2732609

Reputation: 53

How to upload a file to google drive programmatically

can anybody suggest me how to upload a file from my app's local storage directory to google drive using javascript in titanium Appcelerator.

i have tried the following code but it is not uploading the file.. thought some one can help me by seeing this code

code :

 var ggParams = {
clientId: '662194379016.apps.googleusercontent.com',
clientSecret: 'ffRSIWBlXyPwW-M1iQ6DNtXZ',
redirectUri: 'http://localhost', //urn:ietf:wg:oauth:2.0:oob  
devKey: 'AIzaSyBmXhfsc--2CdlSU8UD37Ryyd3qYaUxKls',
};
// Initialize Youtube Service
 var google = new Google(ggParams);
 google.login(function(e){
Ti.API.info('Token: ' + google.accessToken());
}); 
/* google.refreshToken(function(e){
    Ti.API.info('New Token: ' + e.token);

});*/  

 /*var params = {
    call: 'userinfo',
    method: 'GET',
    params: {
        client_id: '662194379016.apps.googleusercontent.com',
        client_secret: 'ffRSIWBlXyPwW-M1iQ6DNtXZ',
        redirect_uri: 'http://localhost', //urn:ietf:wg:oauth:2.0:oob  
        devKey: 'AIzaSyBmXhfsc--2CdlSU8UD37Ryyd3qYaUxKls',
        code:''
        }
};*/
google.callMethod( 
 args = {
    call: 'drive',  //token
    method: 'GET', //POST
    params: {
        clientId: '662194379016.apps.googleusercontent.com',
        clientSecret: 'ffRSIWBlXyPwW-M1iQ6DNtXZ',
        redirectUri: 'http://localhost', //urn:ietf:wg:oauth:2.0:oob  
        devKey: 'AIzaSyBmXhfsc--2CdlSU8UD37Ryyd3qYaUxKls',
         code: 200
        }
},
function(e){

    if (e.success){
        callback(e.data);
        Ti.API.info(e.data);
    }
    else{
        Ti.API.info(e.data);
        Ti.API.error('Error getting tokens');

    }
}, false); //true or false or null

Upvotes: 4

Views: 14266

Answers (1)

GrIsHu
GrIsHu

Reputation: 23638

You need to check for Google API Java Client Upload to Google Docs

This is a sample Android application which uses the google-api-java-client library to demonstrate uploading a file to Google Docs.

This app will

  • Perform OAuth2 authorization against Google Docs
  • Create a folder (known as a collection) in Google Docs
  • Upload a file to Google Docs (inside that folder)
  • Update a file on Google Docs

Take a QuickStart to Google Drive API

Upvotes: 1

Related Questions