Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 324
user2732609 Avatar asked Dec 01 '25 06:12

user2732609


1 Answers

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

like image 175
GrIsHu Avatar answered Dec 03 '25 20:12

GrIsHu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!