【发布时间】:2021-06-25 14:53:38
【问题描述】:
我正在尝试使用 Youtube API v3 运行搜索列表。
我已经运行了quickstart.js,以便按照here 的描述配置我的OAuth2,显然一切都在说This channel's ID is UC_x5XG1OV2P6uZZ5FSM91Ttw. Its title is 'Google Developers', and it has 181445346 views.
打字稿代码:
import express, { Request, Response } from 'express';
import {
google, // The top level object used to access services
Auth, // Namespace for auth related types
} from 'googleapis';
const auth: Auth.GoogleAuth = new google.auth.GoogleAuth();
const youtube = google.youtube({
version: 'v3',
auth,
});
const app = express();
app.get('/', (req: Request, res: Response) => {
youtube.search.list({
part: ['id, snippet'],
maxResults: 10,
q: 'my query search'
})
.then( results => {
res.send(results);
})
.catch( err => {
res.send(err);
})
});
const port = process.env.PORT || 3300;
app.listen(port, () => console.log(`app is listening on PORT: ${port}`))
但我收到以下错误:
Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/Users/username/dev/my-project/node_modules/google-auth-library/build/src/auth/googleauth.js:173:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async GoogleAuth.getClient (/Users/suername/dev/my-project/node_modules/google-auth-library/build/src/auth/googleauth.js:545:17)
at async GoogleAuth.request (/Users/username/dev/my-project/node_modules/google-auth-library/build/src/auth/googleauth.js:598:24)
【问题讨论】:
标签: node.js typescript youtube-data-api google-api-nodejs-client