oauth - 使用 Firebase 进行 oauth 后无法访问 Google plus api

标签 oauth firebase google-plus

2 小时试图让它工作,但我做不到。 Firebase 可以很好地验证用户身份,但它无法从 Google Plus API 获取任何内容。 您将得到的错误:

{
    domain: "global"
    location: "Authorization"
    locationType: "header"
    message: "Invalid Credentials"
    reason: "authError"

}

代码是这样的:

    Auth.$authWithOAuthPopup(provider, {
      scope: ['profile', 'email']
    }).then(function(authData) {

          console.log(authData.token);
          gapi.client.setApiKey('<APIKEY>');
          gapi.client.load('plus','v1', function(){
            var request = gapi.client.plus.people.get({
              'userId': 'me'
            });
            request.execute(function(resp) {
              console.log('Retrieved profile for:' + resp.displayName);
              debugger;
            });
          });

    }, showError);

这一定与 Firebase 代表我们进行调用有关。因为我们在其中进行自己的身份验证的代码笔工作正常: http://codepen.io/morgs32/pen/KVgzBw

不要忘记在代码笔中设置 clientId 和 apiKey。

如果你能解决这个问题,你就会在圣诞节获得金牌。

最佳答案

您正在尝试使用 authData.token 访问 Google。但是 authData.token 是一个用于访问 Firebase 的 JWT token 。

要访问 Google,您应该使用 authData.google.accessToken

另请参阅 Firebase documentation on using the Google provider 中的此页面.

关于oauth - 使用 Firebase 进行 oauth 后无法访问 Google plus api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34448497/

相关文章:

oauth - 为什么 OAuth 设计为具有请求 token 和访问 token ?

android - 如何正确实现linkedIn登录?

asp.net-mvc - 如何更好地控制 DotNetOpenAuth 使用 Microsoft 帐户 (Live ID) 的方式?

android - Firebase 通知 : Easiest way to implement opt-out

javascript - Firebase 消息传递服务工作人员点击处理程序不起作用

android - 如何从适用于 Android 的 Google+ API 获取当前位置?

javascript - 如何在 iframe 中加载 google plus 分享按钮?

swift - 使用 Swift 访问 Twitter

javascript - Firebase 云函数中的嵌套 HTTP 请求

Android 开发 - 任何 Google + SDK 或代码示例?