尝试在我的网络应用上使用 google plus 登录时,不断收到“已超出未经身份验证使用的每日限制。继续使用需要注册”的提示

IT技术 javascript php google-api google-plus
2021-01-29 15:34:16

我正在尝试在我的网络应用程序上实施 Google plus 注册,并且我按照 google 文档设置了注册,但是当我在接受权限并使用返回给我的访问令牌后尝试注册时,我所做的任何 api 调用都会返回已超出未经身份验证的使用的每日限制。继续使用需要注册错误。我已经使用 ouath 2.0 密钥注册了我的应用程序,所以我似乎不明白我做错了什么。这是我的代码。

客户端:

const clientId = "5XXX000XX.apps.googleusercontent.com";
const apiKey = "AIzaSyCAXE5JSa36jcC*X7HV40SBcIWBiVGUTBE";
const scopes = "https://www.googleapis.com/auth/plus.login";
let accessToken = null;

function initer() {
  gapi.client.setApiKey(apiKey);
  // alert("Hello init");
  if ($("#authorize-button").length > 0) {
    $("#authorize-button").click(onLoginClick);
  }
}

function onLoginClick() {
  // $("#modalLoading").modal();
  // alert("yeah");
  gapi.auth.authorize({ client_id: clientId, scope: scopes, immediate: false }, onConnect);
}

function onConnect(authResult) {
  // alert("On connect");
  if (authResult && !authResult.error) {
    alert("Hey");
    accessToken = authResult.access_token;
    triggerLogin();
  } else {
    alert("Error");
  }
}

triggerLogin = function() {
  alert("Triggering login");
  $("#modalLoading").modal();
  $.ajax({
    url: window.config.site_root + "account/google_login",
    type: "POST",
    data: "access_token=" + accessToken,
    success: onLogin,
    error() {
      onError("Logging In", "starting your session");
    },
  });
};

onLogin = function(login) {
  alert("Login start");
  $("#modalLoading").modal("hide");
  if (login.operation) {
    location.reload();
  } else {
    alert("Register will start");
    triggerRegistration();
  }
};

triggerRegistration = function() {
  $("#modalLoading").modal();
  $.ajax({
    url: window.config.site_root + "account/google_registration",
    type: "POST",
    data: "access_token=" + accessToken,
    success: onRegistration,
    error() {
      alert("An Error");
    },
  });
};

onRegistration = function(data) {
  alert("Handling register");
  $("#modalLoading").modal("hide");
  if (data.account_exists) {
    stage.showErrorModal(
      "Account already registered",
      "There is already an account with that email address, are you sure you created an account using this login method?",
    );
  } else if (data.operation) {
    alert("Login now");
    triggerLogin();
  } else {
    alert("Error");
    onError("Registering", "creating your account");
  }
};

这是我的服务器端代码

 public function google_registration()
            {
                $access_token = (isset($_POST["access_token"]) && !empty($_POST["access_token"])) ? $_POST["access_token"] : null;


                $name = null;
                $email = null;
                $account_id = null;
                $picture = null;
                $gender = null;

                try
                {
                    if($access_token)
                    {
                        $me = file_get_contents("https://www.googleapis.com/plus/v1/people/me?access_token=".$access_token);
                        if($me)
                        {
                            $me = json_decode($me);
                            $name = $me->name.formatted;
                            $email = $me->email;
                            $account_id = $me->id;
                            $picture = $me->image;
                            $gender = ($me->gender == "female") ? 1 : 0;
                        }
                    }
                }
                catch(Exception $error)
                {
                    // let the system handle the error quietly.
                }
                return $this->service_registration("google", $name, $email, $account_id, $picture, $gender);

            }
6个回答

我也遇到了同样的错误 - “超出了未经身份验证的使用的每日限制。继续使用需要注册”。

我去检查了我的谷歌开发者控制台在 APIs 下与 API 密钥/身份验证密钥关联的项目,例如,https://console.developers.google.com/project/<your app id>/apiui/apiGoogle+API 的状态设置为 OFF。我打开它。

然后我得到了另一个访问令牌,然后尝试使用新的。它起作用了,即错误消失了,我得到了个人资料的详细信息。为了交叉检查这是否确实是错误的原因,我返回控制台并禁用了 Google+ API。但是现在,我收到错误消息:

“未配置访问权限。请使用 Google Developers Console 为您的项目激活 API。”

所以,我不能 100% 确定这是在我的开发者控制台中打开/关闭 Google+ API,但请确保它已打开。另外,在打开后等待几分钟,并确保每次尝试之前都获得一个新的令牌。

一个注意事项:如果您的项目是谷歌脚本,则您需要访问script.google.com/home/usersettings
2021-03-27 15:34:16
在 Google 控制台启用 API 有效!谢了哥们 :)
2021-04-06 15:34:16

当您已经登录但仍然尝试一次又一次登录时,会发生此问题。我遇到了同样的错误,所以做了一些实验 1) 我在我的手机上打开了网站,一切都很好。2)然后我在另一台笔记本电脑上尝试并使用不同的gmail帐户登录,它再次正常工作。3)在我的第一台笔记本电脑上,我通过单击“登录”按钮再次绑定我遇到了同样的错误,所以我打开 google.com 然后完全注销然后再试一次,这次它起作用了。所以我相信,问题是一次又一次地点击登录按钮而没有注销。

我不确定这是否真的是一个问题,但至少这是我发现的。我仍在尝试,尝试和尝试,如果我发现其他任何东西,我会发布。

干杯!!

这绝对也是我的问题。非常令人困惑,因为 API 都已启用,我正确地传递了所有内容,但是该错误消息很糟糕!我打开了一个隐身窗口,它立即工作。在普通浏览器中注销,然后再次登录,它再次完美运行。谢谢!
2021-04-01 15:34:16

谷歌API

确保您在此处启用了 Google+ Api。

没有它,你会得到如下错误:

"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",

要启用它:

1) 打开https://console.developers.google.com

2)选择你的项目(右上角)

3) 在搜索框中搜索“Google+ API”,如果尚未启用,请启用它。

行。我找到了。但是限制设置为 10 000,我只是测试......低于 20 次。所以它不能修复我的 pb。谢谢
2021-03-19 15:34:16
这似乎又过时了
2021-03-19 15:34:16
我没有给你减分,我只是问一个问题。我收到此错误,但在我的配额屏幕中,我低于最大值。
2021-03-26 15:34:16
没找到这个画面?它在哪里 ?
2021-03-31 15:34:16

您必须添加apiKeyURL:

$curl = curl_init( 'https://www.googleapis.com/urlshortener/v1/url?key=AIza3834-Key' );
从安全的角度来看,这听起来不太好,但是,嘿,它奏效了。+1
2021-04-11 15:34:16

所以我遇到了这个问题,上述两种方法/解决方案(启用 API 访问和注销帐户)对我不起作用,因为对于 google+ 登录,您必须在 http 调用的授权标头中传递访问令牌。

以下是您如何通过 jQuery 执行此操作:

    $.ajax({
      type: "GET", 
      url: "https://www.googleapis.com/plus/v1/people/me",
      headers: {
       "Authorization":"Bearer " + {access_token},
      }
    });

您的问题似乎出在服务器端代码上,您在该代码中传入了 params 中的 access_token(这不是必需的)。

这是我对 PHP 实现的尝试:

$opts = array(
'http'=>array(
 'method'=>"GET",
 'header'=>"Authorization: Bearer ".$access_token 
 )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('https://www.googleapis.com/plus/v1/people/me', false, $context);'
尽管官方文档确实声明您可以将 access_token 作为 Query 参数或在标头中传递,但在 Query 中传递它时我总是收到该错误。它仅在作为标头传递时才有效。它说:“通过包含 access_token 查询参数或 Authorization: Bearer HTTP 标头,在对 API 的请求中包含访问令牌”。这是链接:developers.google.com/identity/protocols/OAuth2WebServer
2021-03-26 15:34:16