1
votes

Faced this strange issue while creating a folder using the google drive API. The number of requests being sent from the browser is only 1 and as part of the response I get a single folder created. But after about 5-10 seconds the second folder is created automatically.

The request payload contains the following request

({mimeType: "application/vnd.google-apps.folder", parents: [{id: "root"}], title: "expenseapp"})

The javascript Code being executed is mentioned below. Unable to figure out why two folders are created as part of this request. The same request when posted through the google Try it link Google Try It Link, creates only a single folder. Went through the request line by line too and could find only (x-client-data:CKi1yQEIjbbJAQimtskBCKm2yQEIwbbJAQjuiMoBCLaVygE=) this additional header info when posted from the Try it link which was not present when this was posted programatically

    var CLIENT_ID = "<CLINET ID>";
    var API_KEY = "AIzaSyAUHmII94uYsdu8_V_P-bRXkGQECKwPun8";
    var SCOPES = ["openid", "profile", "email", "https://www.googleapis.com/auth/drive"];
    gapi.client.setApiKey(API_KEY);
    var _this = this;
    gapi.auth.authorize({'client_id' : CLIENT_ID,'scope': SCOPES,'immediate': true},function(){
        console.log('Entered');
        gapi.client.load('drive', 'v2',_this.createFolder );
    });
createFolder : function(){
        var auth = 'Bearer accessToken';
        var _this = this;
        var request = gapi.client.request({
            path : 'https://www.googleapis.com/drive/v2/files',
            method : 'POST',
            params : "",
            headers : {
                'Authorization' : auth,
                'Content-Type': 'application/json'
            },
            body : {
                "mimeType": "application/vnd.google-apps.folder",
                "parents": [{"id":"root"}],
                "title" : "expenseapp"
            }
        })
         request.execute(function(resp){
            console.log('Created File id :'+resp.id);
         })


}
1

1 Answers

0
votes

Could not figure out the actual solution, but deleting the app from the google developer console and creating a new one has fixed the problem. Might have been a peculiar bug.