• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

googleapis/google-api-nodejs-client: Google's officially supported Node.js c ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

googleapis/google-api-nodejs-client

开源软件地址(OpenSource Url):

https://github.com/googleapis/google-api-nodejs-client

开源编程语言(OpenSource Language):

TypeScript 99.5%

开源软件介绍(OpenSource Introduction):

Google Inc. logo

Google APIs Node.js Client

npm version Downloads Dependency Status Known Vulnerabilities

Node.js client library for using Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT tokens is included.

Google APIs

The full list of supported APIs can be found on the Google APIs Explorer. The API endpoints are automatically generated, so if the API is not in the list, it is currently not supported by this API client library.

Working with Google Cloud Platform APIs?

If you're working with Google Cloud Platform APIs such as Datastore, Cloud Storage or Pub/Sub, consider using the @google-cloud client libraries: single purpose idiomatic Node.js clients for Google Cloud Platform services.

Support and maintenance

These client libraries are officially supported by Google. However, these libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features. For Google Cloud Platform APIs, we recommend using google-cloud-node which is under active development.

This library supports the maintenance LTS, active LTS, and current release of node.js. See the node.js release schedule for more information.

Getting started

Installation

This library is distributed on npm. In order to add it as a dependency, run the following command:

$ npm install googleapis

If you need to reduce startup times, you can alternatively install a submodule as its own dependency. We make an effort to publish submodules that are not in this list. In order to add it as a dependency, run the following sample command, replacing with your preferred API:

$ npm install @googleapis/docs

You can run this search on npm, to find a list of the submodules available.

Using the client library

This is a very simple example. This creates a Blogger client and retrieves the details of a blog given the blog Id:

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

// Each API may support multiple versions. With this sample, we're getting
// v3 of the blogger API, and using an API key to authenticate.
const blogger = google.blogger({
  version: 'v3',
  auth: 'YOUR API KEY'
});

const params = {
  blogId: '3213900'
};

// get the blog details
blogger.blogs.get(params, (err, res) => {
  if (err) {
    console.error(err);
    throw err;
  }
  console.log(`The blog url is ${res.data.url}`);
});

Instead of using callbacks you can also use promises!

blogger.blogs.get(params)
  .then(res => {
    console.log(`The blog url is ${res.data.url}`);
  })
  .catch(error => {
    console.error(error);
  });

Or async/await:

async function runSample() {
  const res = await blogger.blogs.get(params);
  console.log(`The blog url is ${res.data.url}`);
}
runSample().catch(console.error);

Alternatively, you can make calls directly to the APIs by installing a submodule:

const docs = require('@googleapis/docs')

const auth = new docs.auth.GoogleAuth({
  keyFilename: 'PATH_TO_SERVICE_ACCOUNT_KEY.json',
    // Scopes can be specified either as an array or as a single, space-delimited string.
  scopes: ['https://www.googleapis.com/auth/documents']
});
const authClient = await auth.getClient();

const client = await docs.docs({
    version: 'v1',
    auth: authClient
});

const createResponse = await client.documents.create({
    requestBody: {
      title: 'Your new document!',
    },
});

console.log(createResponse.data);

Samples

There are a lot of samples


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap