javascript - 使用 REST 端点获取 Youtube Data API v3 OAuth2 令牌时出现问题
问题描述
我一直在尝试使用以下代码在本机反应中获取 YouTube OAuth2 令牌:
let url =
'https://accounts.google.com/o/oauth2/v2/auth?' +
new URLSearchParams({
client_id: encodeURIComponent(clientId),
redirect_uri: encodeURIComponent('http://localhost:19006/oauth2callback'),
scope: encodeURIComponent('https://www.googleapis.com/auth/youtube'),
response_type: 'token'
});
//Fetch the URL
fetch(url)
.then(function (response) {
// Log and return the response as JSON
let rJson = response.json();
console.log(rJson);
return rJson;
})
.then(function (data) {
// Log the API data
console.log('token', data);
})
.catch(function (err) {
// Log any errors
console.log('something went wrong', err);
});
我收到错误消息:
SyntaxError: JSON Parse error: Unrecognized token '<'
即使在查看YouTube Data API Client-side Web Apps Docs之后,我也一直坚持这一点,毫无疑问,这很简单,我看不到,但我们将不胜感激
解决方案
推荐阅读
- ruby-on-rails - Heroku Rails 部署问题
- python - Tensorflow:输出最大值为1,其余为0
- microsoft-teams - pulseaudio“别名”接收器,由(运行时可切换)其他接收器支持
- javascript - JavaScript - 创建一个按顺序调用事件的按钮
- mysql - 在 google cloud 上运行的 Lamp stack 并想创建一个副本数据库
- javascript - 无法使用 three.js 更改我的 3D 模型的颜色
- c# - C#/Selenium .Net 转换 ro .Core 错误
- python - 来自 fortran 的数字太大:ValueError:无法将字符串转换为浮点数:'0.22738+109'
- javascript - For Loop Google App Script Javascript 的更快替代方案
- html - 当用户在日历上选择其他日期时,PrimeNG 日历清除当前/今天日期