继续获得“超出未经身份验证使用的每日限制”。继续使用需要注册“时,尝试谷歌并登录我的网络应用程序

2022-08-30 09:30:38

我正在尝试在我的Web应用程序上实现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);

            }

答案 1

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

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

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

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

因此,我不能100%确定它是在我的开发人员控制台中打开/关闭Google+ API,但请确保将其打开。此外,请在打开后等待几分钟,并确保每次在尝试之前都获得新的令牌。


答案 2

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

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

干杯!!