basconstruction.blogg.se

Google drive api nodejs
Google drive api nodejs











google drive api nodejs

In our case the file would be created on the service accounts google drive account. If you don’t supply a directory the file will be created in the root google drive folder of the currently authenticated user. Create a service account initialize with the service account key file and scope neededĬonst auth = new () Create new fileĬreating new files on google drive is done in two parts The first part of creating a new file is the metadata, name, description, type of the file, and the directory where you would like it created. We do this by calling GoogleAuth and passing it the keyfile and the scopes we will be using. In order to use the service account in our code we will need to initialize.

google drive api nodejs google drive api nodejs

Request full drive scope and profile scope, giving full access to google drive as well as the users basic profile information.Ĭonst SCOPES = Initialize service account Scopes is a comma separated array you can add more than one. service account key file from Google Cloud console.Ĭonst KEYFILEPATH = 'C:\\Youtube\\dev\\ServiceAccountCred.json' So I will be questing the full drive scope. In our case the user is the service account, the amount of access it needs is quite high because it needs to be able to write to Google drive. Scopes are used to define the amount of access the authenticated user is granted when access the api. The second will define the scope that our application will need in order to upload files. The first will be the location of the Json service account key file, which we downloaded earlier form Google Cloud console. I will be setting up a couple of constants in my script. The googleapis package will install all the methods we will need to authorize our service account as well as access the Google drive api from Node js. In order to access the google drive api with node js we will need to install the googleapis package. The Google apis Node js client library is one of these libraries. Google has been kind enough to create client libraries which we can use to access their apis. Remember to go to library and enabled the Google drive api after that dont forget to download a json key file. So the very the first thing we will need to do is to go to Google Cloud console and create service account credentials. We identify our application by creating a project on Google Cloud console, we set up authorization by creating service account credentials and downloading the Json Key file. In order to access Google APIs we need to identify our application, as well as in the case of accessing private user data we need to be authorized to access that private data.













Google drive api nodejs