【发布时间】:2019-05-16 11:01:51
【问题描述】:
我被困住了。我正在尝试在 Angular 中创建 Google People API 身份验证服务。
我在 Chrome 控制台中遇到错误:
Uncaught (in promise): TypeError: Cannot read property 'people' of undefined
谁能帮我理解为什么?
declare var gapi: any;
@Injectable({
providedIn: 'root'
})
export class AuthService {
user$: Observable<firebase.User>;
peopleItems: any[];
constructor(public afAuth: AngularFireAuth) {
this.initClient();
this.user$ = afAuth.authState;
}
initClient() {
gapi.load('client', () => {
gapi.client.init({
apiKey: 'myapikey',
clientId: '',
discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/people/v1/rest"],
scope: 'https://www.googleapis.com/auth/contacts'
})
});
}
async getPeople() {
const mypeople = await gapi.client.people.people.connections.list({
resourceName: 'people/me',
personFields: 'names,emailAddresses',
})
this.peopleItems = mypeople.people.people.list;
}
}
【问题讨论】:
-
可能是因为
mypeople.people或mypeople未定义。 -
谢谢。我将 this.peopleItems = mypeople.people.people.list 更改为 mypeople.result.connections。
-
@GregHarner 请标记答案
-
我不确定“标记答案”是什么意思。我确实继续并单击橙色 ^ 图标。这是一个答案吗?
-
好的,我从帮助中看到没有标记答案。但是,我没有看到允许我标记答案的按钮。它藏在哪里?
标签: angular google-api