Node.js Google Drive: Generate a Set of File IDs

Back to Index

Generates a set of file IDs which can be provided in create requests.

Documentation: https://developers.google.com/drive/v3/reference/files/generateIds


var os = require('os');
if (os.platform() == 'win32') {  
    var chilkat = require('chilkat_node6_win32'); 
} else if (os.platform() == 'linux') {
    if (os.arch() == 'arm') {
        var chilkat = require('chilkat_node6_arm');
    } else if (os.arch() == 'x86') {
        var chilkat = require('chilkat_node6_linux32');
    } else {
        var chilkat = require('chilkat_node6_linux64');
    }
} else if (os.platform() == 'darwin') {
    var chilkat = require('chilkat_node6_macosx');
}

function chilkatExample() {

    var rest = new chilkat.Rest();
    var success;

    //   Provide a previously obtained OAuth2 access token.
    var oauth2 = new chilkat.OAuth2();
    oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN";
    rest.SetAuthOAuth2(oauth2);

    success = rest.Connect("www.googleapis.com",443,true,true);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    rest.AddQueryParam("count","20");
    rest.AddQueryParam("space","drive");

    var sbJson = new chilkat.StringBuilder();
    success = rest.FullRequestNoBodySb("GET","/drive/v3/files/generateIds",sbJson);
    if (success !== true) {
        console.log(rest.LastErrorText);
        return;
    }

    if (rest.ResponseStatusCode !== 200) {
        console.log("Received error response code: " + rest.ResponseStatusCode);
        console.log("Response body:");
        console.log(sbJson.GetAsString());
        return;
    }

    var json = new chilkat.JsonObject();
    json.LoadSb(sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.
    var kind;
    var space;
    var i;
    var count_i;
    var strVal;

    kind = json.StringOf("kind");
    space = json.StringOf("space");
    i = 0;
    count_i = json.SizeOfArray("ids");
    while (i < count_i) {
        json.I = i;
        strVal = json.StringOf("ids[i]");
        i = i+1;
    }

    console.log("Example Completed.");

}

chilkatExample();

Sample JSON Response Body

{
  "kind": "drive#generatedIds",
  "space": "drive",
  "ids": [
    "1IT3VaUqXuF4l_4UKAFSmmC0em6kwlkle",
    "1dX50zZmgzwDUonE_GI59oTF1D7RRYD3o",
    "1eH17RULdRXu03inCaNuSeYkNwPS2nfUZ",
    "1jXHKTHe6LazdWV0wPl8xAeHEoo_ZMBVt",
    "1eBH9E3XDEczuUyfeOXT4Abq8S343qt5r",
    "1R3okvS4vI1f1Psg0IJJ3dIhVQsv9SNyY",
    "1rrh7NzGCgK0gYFlHC3IUdqQjcsVInN76",
    "1glhBVDGFgS-61B_l0HaHBGiMRwyhuzp_",
    "1gou1y4Mrq_ETHW7-GMV53e2jlhnze_2A",
    "1KSUwFR7E9iDxpcLO8_hr6nnLUXGR0kAY",
    "1pWt-cW7IBeEyGAkOxu8Q1KUpoHCkjGB2",
    "1nnuZfxcmvq_nmHDKZLvKfohYFbs2X1q_",
    "1rCGGTlP9aU9KNj_Qnt1a4ea3WdbV3NGk",
    "1pLDQjyeBQvYOehHvW9mfzRzMp6yA-HOZ",
    "1Ea-LO9eiwRlgJ-XvpFRxZUje1kFwaEBq",
    "1nXtRHiCcIhXtY3YVcKmArlrljM2eLoGp",
    "1g1VldY1fC3-w0JPycgUOU1mC524r5AHH",
    "1lh1cKumE6jMc-FTfPk7y0V3jqzGydzyQ",
    "1ZPdHqv3NI8tdVJ2k_XBr8cpkJYuq1E6c",
    "1bxfXQmmrOUCnkZJogavDd6CF0eMSAzo9"
  ]
}