vuejs2 - 如何使用 VueJS axios-oauth-client 和 google photos api?
问题描述
我正在使用 vue cli,并尝试从我的谷歌照片帐户中获取专辑列表。
我正在使用 axios-oauth-client 并尝试实现此代码:
const axios = require('axios');
const oauth = require('axios-oauth-client');
const getAuthorizationCode = oauth.client(axios.create(), {
url: 'https://oauth.com/2.0/token',
grant_type: 'authorization_code',
client_id: 'foo',
client_secret: 'bar',
redirect_uri: '...',
code: '...',
scope: 'baz',
});
const auth = await getAuthorizationCode(); // => { "access_token": "...", "expires_in": 900, ... }
如此处所述,我不明白如何在此实现中获取授权代码,也就是代码。
我设法在邮递员中进行了此调用,但无法使用 axios 进行此调用。
我的代码
async function getToken() {
const getAuthorizationCode = oauth.client(axios.create(), {
url: "https://oauth2.googleapis.com/token",
grant_type: "authorization_code",
client_id:
"**********.apps.googleusercontent.com",
client_secret: "***********",
redirect_uri: "http://localhost:8080/oauth2/callback",
code: "...",
scope: "https://www.googleapis.com/auth/photoslibrary.readonly"
});
const auth = await getAuthorizationCode(); // => { "access_token": "...", "expires_in": 900, ... }
console.log(auth);
}
getToken();
我究竟做错了什么?
谢谢!
更新
我仍然没有设法让它工作,但我找到了这个答案,我会尝试检查。
更新#2
最终,我最终使用 php 使用了 Oauth2 的 google文档,并将他们的 git 示例作为基础项目。为了做到这一点,我还需要使用数据库来保存令牌,尤其是每次收到 401 时我用来刷新访问令牌的刷新令牌。
解决方案
推荐阅读
- python-3.x - 从 pmdarima.model_selection 导入 train_test_split 不工作
- firebase - 如何限制用户仅在 1 个设备中使用 1 个电子邮件 ID 或电话号码
- sql-server - 什么在sql server中创建和删除表的索引
- node.js - 如何从 axios 请求中获取原始响应数据?
- azure - Azure Key Vault 如何确定特定密钥是否为当前密钥?
- php - 没有用户界面的 Xero API 集成(machine-2-machine)
- javascript - 在这种情况下,我如何理解 Promise all?
- database - 从函数中截断表不适用于特定的 postgresql 表
- python - 如何创建熊猫数据框并从函数中填充它?
- pandas - 如何使用颜色条指定数据相对于某些范围的变化