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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19335503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 19:18:23  来源:igfitidea点击:

Keep getting a "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup" when attempting to google plus login on my web app

javascriptphpgoogle-apigoogle-plus

提问by Michael Nana

I'm trying to implement Google plus sign up on my web app and I followed the google docs to set up the sign up however when I attempt a signup after accepting permissions and using the access token returned to me any api restcall I make returns the Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup error. I have already signed up my app with a ouath 2.0 key, so I don't seem to get what I'm doing wrong. Here is my code.

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

Cient Side:

客户端:

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");
  }
};

Here is my server side code

这是我的服务器端代码

 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);

            }

回答by user3392439

I too ran into the same error - "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup".

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

I went and checked my google developer console under APIs for the project associated with the API key/ auth key, eg, https://console.developers.google.com/project/<your app id>/apiui/api. The status for Google+API was set to OFF. I turned it ON.

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

I then got another access token, and then tried with the new one. It worked, ie, the error was gone and I got the profile details. To cross-check if that was indeed the cause of the error, I went back to console and disabled Google+ API. But now, I get the error:

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

"Access Not Configured. Please use Google Developers Console to activate the API for your project."

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

So, I am not 100% sure that it was the turning on/off of the Google+ API in my developer console, but do ensure that this is turned on. Also, wait a few minutes after turning on, and ensure that you get a fresh token each time before trying it.

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

回答by www.amitpatil.me

This issue happens when you are already logged in and still try to login again and again. I faced same error so did some experiments 1) I opened website on my mobile and everything was fine. 2) Then i tried on another laptop and used different gmail account to login and it again worked fine. 3) On my first laptop i tied again by clicking "Signin" button i got same error, so i opened google.com then logged out completely and then tried again, this time it worked. So i believe, Issue is clicking login button again and again without logout.

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

I am not sure if this is a really a issue, but atleast this is what i found. I am still trying, trying and trying , will post if i found anything else.

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

Cheers !!

干杯!!

回答by Mantas D

google api

谷歌API

Make sure you have Google+ Api here enabled.

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

Without it you will get errors like:

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

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

To enable it:

要启用它:

1) open https://console.developers.google.com

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

2) choose your project (top right corner)

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

3) search for "Google+ API" in search box and enable it if it is not enabled already.

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

回答by Mehwish Rais Siddiqui

You have to add the apiKeywith the URL:

您必须添加apiKeyURL:

$curl = curl_init( 'https://www.googleapis.com/urlshortener/v1/url?key=AIza3834-Key' );

回答by superjisan

So I ran into this issue and the above two methods/solutions (enabling API access, and signing out of accounts) did not work for me because for google+ signin you have to pass in the access token in the authorization header of the http call.

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

Here's how you do it via jQuery:

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

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

It seems your issue is with the server side code where you pass in access_token in the params (which is not necessary).

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

Here's my attempt on what the PHP implementation would look like:

这是我对 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);'

回答by Ian Barber

Hopefully you're sending that access token over https! It might be worth considering using the code instead and doing an exchange on the server side for an access token, for improved security if nothing else, there's some documentation on that approach here: https://developers.google.com/+/web/signin/server-side-flow

希望您通过 https 发送该访问令牌!可能值得考虑使用代码代替并在服务器端交换访问令牌,为了提高安全性,如果没有别的,这里有一些关于这种方法的文档:https: //developers.google.com/+/web /登录/服务器端流程

With regards to the problem you're seeing, it seems like the access token is bad, or not making it through correctly. Can you check the access token that you receive against the tokeninfo endpoint: https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=- that should show valid information. Nothing stands out as being off in the code, but if the token is getting mangled you might see a similar error.

关于您看到的问题,似乎访问令牌不好,或者没有正确通过。您能否根据 tokeninfo 端点检查收到的访问令牌:https: //www.googleapis.com/oauth2/v1/tokeninfo?access_token =- 应该显示有效信息。代码中没有任何内容是关闭的,但是如果令牌被损坏,您可能会看到类似的错误。

回答by Minh Ti?n

I got have the same issue, The solution is: set APIKEY

我有同样的问题,解决方案是:设置 APIKEY

回答by Luca Fritz Ferrari

I was also desperate, and finally I managed to find a solution. The only problem is to add the correct api token linked to your app, in my case was the browser token, and it all works.

我也很绝望,最后我设法找到了解决办法。唯一的问题是添加链接到您的应用程序的正确 api 令牌,在我的情况下是浏览器令牌,并且一切正常。

Example: I wanted to have all the events associated with my calendar

示例:我希望将所有事件与我的日历相关联

https://www.googleapis.com/calendar/v3/calendars/{calendar_id}/events?&key={api_key}

https://www.googleapis.com/calendar/v3/calendars/{calendar_id}/events?&key={api_key}

maybe I will help someone who is having the same problem.

也许我会帮助遇到同样问题的人。

Good Luck

祝你好运

回答by Thamaraiselvam

In my case, it happened at a specific time of the day, After spending few hours finally found that my daily quota limit (Queries per 100 seconds) was exceeded at that time because of a high number of requests. so it was throwing the error. I have contacted google support to increase them.

就我而言,它发生在一天中的特定时间,花了几个小时后终于发现由于大量请求,当时超出了我的每日配额限制(每 100 秒的查询数)。所以它抛出了错误。我已经联系了谷歌支持以增加它们。

回答by Nahuel

In my case, it was because I was using an old access token. You must keep in mind that access tokens have a short life span, so you must use the refresh token to generate a new access token. Example (using a PHP Class):

就我而言,这是因为我使用的是旧的访问令牌。您必须记住访问令牌的生命周期很短,因此您必须使用刷新令牌来生成新的访问令牌。示例(使用 PHP 类):

// Get the access token from DB or filesystem
$accessToken = $this->getAccessToken();
// Set the access token
$this->client->setAccessToken($accessToken);

// Refresh the token if it's expired.
if ($this->client->isAccessTokenExpired()) {
    $this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken());
    // Save the new access token to DB or filesystem
    $this->saveAccessToken($this->client->getAccessToken());
}