Javascript 谷歌';s人员Api:can';无法从Vuejs应用程序获取组织信息
我目前正在实施Google Oauth身份验证流来访问我的Vuejs 2应用程序 我正在使用这个npm:它封装了使用GoogleAPI和GoogleAuthentication执行客户端操作所需的脚本 我需要请求Google People API获取用户的组织信息 我确保正确设置discoveryDocs和范围,以便我可以要求使用People Api。 以下是我的实现:Javascript 谷歌';s人员Api:can';无法从Vuejs应用程序获取组织信息,javascript,api,vue.js,google-people-api,Javascript,Api,Vue.js,Google People Api,我目前正在实施Google Oauth身份验证流来访问我的Vuejs 2应用程序 我正在使用这个npm:它封装了使用GoogleAPI和GoogleAuthentication执行客户端操作所需的脚本 我需要请求Google People API获取用户的组织信息 我确保正确设置discoveryDocs和范围,以便我可以要求使用People Api。 以下是我的实现: // main.js import Vue from 'vue' import VueGoogleApi from 'vue
// main.js
import Vue from 'vue'
import VueGoogleApi from 'vue-google-api'
const config = {
apiKey: 'AIzxxxxxxxxx-xxxxxxxxxxBQmXzc',
clientId: 'xxxxxxxxxxx-xxxxxxxxxxxxxx.apps.googleusercontent.com',
discoveryDocs: ['https://people.googleapis.com/$discovery/rest?version=v1'],
scope: 'https://www.googleapis.com/auth/user.organization.read'
}
Vue.use(VueGoogleApi, config)
我的简化登录组件:
//LoginPage.vue
<template>
<div>
<a @click="loginWithGoogle">Connexion with Google</a>
</div>
</template>
<script>
export default {
methods: {
async loginWithGoogle() {
try {
const user = await this.$gapi.signIn()
if (user) {
console.log('Signed in as %s', user.name)
// request to People API
const userInfosResponse = await this.$gapi.request({
path: 'https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses,organizations',
method: 'GET',
params: {
personFields: 'names,emailAddresses,organizations'
}
})
console.log(userInfosResponse);
}
} catch (e) {
console.error(e)
}
}
}
}
<script>
userInfosResponse
预期响应为:
// simplified json object
{
"result": {
"resourceName": "people/10007798281xxxxx",
"etag": "xxx",
"names": [
{...}
],
"emailAddresses": [
{...}
],
"organizations": [
{...}
]
},
"status": 200,
"statusText": "OK"
}
问题是我以前成功地获取了组织数据,但后来我尝试了$this.gapi.signOut()
我再也无法获取这些信息了
提前谢谢 我通过停止使用包装Google API函数的模块解决了我的问题。我在VueJs项目中的index.html文件中找到了一个本地API,从而知道了如何从google导入本地API。现在我可以得到我想要的数据了
// simplified json object
{
"result": {
"resourceName": "people/10007798281xxxxx",
"etag": "xxx",
"names": [
{...}
],
"emailAddresses": [
{...}
],
"organizations": [
{...}
]
},
"status": 200,
"statusText": "OK"
}