我正在使用嵌入API在Vue应用程序中创建一个报告。
我遵循以下文档:在访问令牌到期之前,https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth所有东西都可以工作。我捕捉到错误,从后端获取一个新的access_token,并调用授权来重新验证嵌入api客户端。
await window.gapi.analytics.auth.authorize({
serverAuth: {
access_token: <my token>
}
})
const isAuthorized = await window.gapi.analytics.auth.isAuthorized()
// isAuthorized returns true
// however getAuthResponse() still returns the old expired token.
console.log('getAccessToken', await window.gapi.analytics.auth.getAuthResponse().access_token)
// and the call to get the reporting data fails as the authorization header is the old expired header
const data = new window.gapi.analytics.report.Data({ query: params })当access_token在我的spa应用程序中过期后,如何更新它,以便嵌入api对服务帐户进行重新身份验证?
发布于 2022-02-10 12:40:18
google分析嵌入式api基于Javascript。它建立在后端的Google js客户机库之上。
JavaScript是隐式流,这意味着您将不会得到返回给您的刷新令牌。服务帐户也不适用于JavaScript。
开箱即用,您唯一的选择是在访问令牌过期时再次请求用户登录到您的应用程序。
我见过/听说过一些开发人员,他们设法将服务器端授权组件黑入其中,例如,使用node.js使用oauth2或服务帐户来刷新授权。这是您自己编写代码所需要的,api不支持它。
https://stackoverflow.com/questions/71026125
复制相似问题