Reputation: 71
I've been some hours trying to do this, but i can't never get the data i'm trying to get. Do i need to do the request other way or something? there's my code:
doGoogleLogin(){
return new Promise<any>((resolve, reject) => {
let provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
provider.addScope('https://www.googleapis.com/auth/user.birthday.read');
provider.addScope('https://www.googleapis.com/auth/user.gender.read');
this.afAuth.auth
.signInWithPopup(provider)
.then(res => {
resolve(res);
console.log(res.additionalUserInfo.profile['id']);
this.http
.get("https://people.googleapis.com/v1/people/"+res.additionalUserInfo.profile['id']+"?key=(a valid api key)&personFields=birthdays,genders")
.subscribe(data => (console.log(data)));;
}, err => reject(err))
})
}
What i usually get in data, from the http request is only:
{
"resourceName": "people/101296298961277932659",
"etag": "%EgQBBzcuGgQBAgUH"
}
And i should be getting 2 more objects containing the birthdate and gender, but it never happen.
Upvotes: 2
Views: 2609
Reputation: 421
Using Sebas his answer I managed to get the People API working with my Firebase code, I'll post it here for others:
First Enable the API in the Developer Console.
import firebase from 'firebase/app'
let provider = new firebase.auth.GoogleAuthProvider()
provider.addScope('profile')
provider.addScope('email')
provider.addScope('https://www.googleapis.com/auth/user.birthday.read')
provider.addScope('https://www.googleapis.com/auth/user.gender.read')
firebase
.auth()
.signInWithPopup(provider)
.then(res => {
fetch(
`https://people.googleapis.com/v1/people/${res.additionalUserInfo.profile.id}?personFields=birthdays,genders&access_token=${res.credential.accessToken}`
).then(response => console.log(response))
})
Upvotes: 3
Reputation: 71
I've resolved this, 50% thanks to Vilsad P P in the comment below the post.
I searched how to put the access token in the url, and after some time i found the parameter "access_token", just put it in the url like this:
https://people.googleapis.com/v1/people/(user_id)?personFields=(fields you want)&key=(valid api key)&access_token=(accessToken in credetials in the result of the authentification)
Upvotes: 1