Whether to use googleapis or google-cloud library for node js

风格不统一 提交于 2019-12-23 12:33:54

问题


I see there are two available libraries. I am wondering what are the differences? Are they both officially maintained by Google?

https://www.npmjs.com/package/googleapis

https://www.npmjs.com/package/google-cloud


回答1:


Yes both are maintained by Google. googleapis covers all these APIs (drive, calendar, admin sdk, maps, etc) whereas google-cloud covers the cloud platform stuff like bigquery, datastore, cloud storage, bigtable, pub/sub, etc. There appears to be overlap and I don't know which one is better for a particular service. Will be playing with cloud storage and admin sdk here soon though :)




回答2:


The answer is found here.

From the reference, the @google-cloud library is recommended as it has the following benefits:

  • In some cases, gives you performance benefits by using gRPC. You can find out more in the gRPC APIs section below.
  • @googleapis " has autogenerated interface code that may not be as idiomatic as our newer libraries."

Personally, I think if you are using non-cloud APIs like Gmail, Calendar, etc, it may be more worth it to use just the Google APIs library for syntactic consistency.

One thing I noticed is that the @google-cloud library didn't allow the same authentication method that I like using with @googleapis:

const { google } = require('googleapis');

new google.auth.JWT(client_email, null, private_key, [
        'https://www.googleapis.com/auth/cloud-platform'
    ]);


来源:https://stackoverflow.com/questions/42866009/whether-to-use-googleapis-or-google-cloud-library-for-node-js

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