在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:googleapis/google-api-nodejs-client开源软件地址:https://github.com/googleapis/google-api-nodejs-client开源编程语言:TypeScript 99.5%开源软件介绍:Google APIs Node.js ClientNode.js client library for using Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT tokens is included.
Google APIsThe 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 Support and maintenanceThese 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 startedInstallationThis library is distributed on $ 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 libraryThis 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); SamplesThere are a lot of samples |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论