Use of node.js with Google Drive API insert / upload

…衆ロ難τιáo~ 提交于 2019-12-11 01:59:52

问题


The documentation at https://developers.google.com/drive/v2/reference/files/insert for JavaScript is intended for use of the client-side JS library. Trying to use the corresponding node.js library, I'm running into problems calling request(), since there doesn't appear to be one.

Short of making the network call directly without use of the library, is there an equivalent for the gapi.client.request() function?


回答1:


I was also looking for similar alternative when using nodejs and calling Google drive API. I am using googleapi. Following code snippet might help to give idea on API.

   googleapis
    .discover('drive', 'v2')
    .execute(function(err, client) {
        req = client.drive.files.list()
        console.log(req);
        req.execute(function(err, result) {
            console.log(err);
            console.log(result);
        });
    });



回答2:


Not familiar with the Node libary, but typically with Googleapis, you can use the apiclient discovery to build an api service.

You should be able to use the Node API Client to build the Drive service, then call the files.insert method on your service object. https://github.com/google/google-api-nodejs-client/blob/master/lib/googleapis.js




回答3:


This is still VERY much a work in progress, but it does show how to use the official node.js googleapis module. It looks like they've made good progress since I originally came up with this solution so I'll likely update my approach and the GIST to use OAuth2 rather than JWT very soon.

VERY basic example of how to save content to Google Drive using node.js using googleapis.



来源:https://stackoverflow.com/questions/17100694/use-of-node-js-with-google-drive-api-insert-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!