firebase Facebook oAuth addScope()



我正在使用带有angular的firebase和带有firebase facebook提供商的oAuth。一切正常。 但是,当我尝试为示例添加新范围 (user_friends( 时,我没有得到任何数据(弹出窗口要求我提供正确的范围(:

//auth.service.ts
signInWithFacebook() {
const provider =  new firebase.auth.FacebookAuthProvider();
provider.addScope("user_friends");
return this.oAuthLogin(provider);
}
private oAuthLogin(provider) {
return this._firebaseAuth.auth.signInWithPopup(provider)
.then((credential) => {
this.updateUserData(credential.user)
})
}

因此,凭据像往常一样获得了基本用户信息(displayName,photoUrl(。 我试图寻找返回的承诺作为回调:

type UserCredential = {
additionalUserInfo?: firebase.auth.AdditionalUserInfo | null;
credential: firebase.auth.AuthCredential | null;
operationType?: string | null;
user: firebase.User | null;
};

我们可以看到有一个 firebase.user 获得了很多方法,但没有为我的新范围添加字符串。

interface UserInfo {
displayName: string | null;
email: string | null;
phoneNumber: string | null;
photoURL: string | null;
providerId: string;
uid: string;
}

因此,我看不到如何将我的user_friends数据(数组(如下(添加到凭据数据(哪种方法?(中并显示在我的控制台中。

"friends": {
"data": [
//friends id and their name
],
"summary": {
"total_count": 631
}
}

感谢您的帮助!

我实际上找到了一个解决方案,并希望为像我这样的失落灵魂分享。

1( addScope(( 方法只是在 oAuth 弹出窗口中询问其他范围的方法,回调中没有提供数据。

2(获得Facebook的额外范围需要通过AccessToken通过graphUrl完成,就像API一样

。3(这里的代码来获得一个可行的访问令牌:

private oAuthLogin(provider) {
return this._firebaseAuth.auth.signInWithPopup(provider)
.then((result) => {
this.token = result.credential["accessToken"];
this.updateUserData(result.user)
})
}

firebase/js 文档通过 result.credential.accessToken 获取 AccessToken,但在许多情况下它会生成打字稿错误(很多人收到此错误消息(。

因此,获取Facebook好友列表(使用GraphUrl(例如:

getFacebookFriendsList() {
var graphUrl = 'https://graph.facebook.com/me/friends?access_token=' + this.token;
return this.http.get(graphUrl);
}

最新更新