Javascript 不断得到一个“答案”;超出未经验证使用的每日限制。继续使用需要注册”;尝试在我的web应用上使用google plus登录时

Javascript 不断得到一个“答案”;超出未经验证使用的每日限制。继续使用需要注册”;尝试在我的web应用上使用google plus登录时,javascript,php,google-api,google-plus,Javascript,Php,Google Api,Google Plus,我正在尝试在我的web应用程序上实现Google plus注册,我按照Google文档设置了注册。但是,当我在接受权限并使用返回给我的访问令牌后尝试注册时,我所做的任何api重新调用都会返回未经验证使用的每日限制。继续使用需要注册错误。我已经用ouath 2.0密钥注册了我的应用程序,所以我似乎不知道我做错了什么。这是我的密码 西恩方面: const clientId = "5XXX000XX.apps.googleusercontent.com"; const apiKey = "AIzaSy

我正在尝试在我的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);

            }

希望您正在通过https发送访问令牌!可能值得考虑改用代码,并在服务器端交换访问令牌,为了提高安全性(如果没有其他原因的话),这里有一些关于这种方法的文档:


关于您看到的问题,似乎访问令牌坏了,或者没有正确通过。您是否可以对照tokeninfo端点检查您收到的访问令牌:-该端点应显示有效信息。在代码中,没有什么会因为关闭而突出,但是如果令牌被损坏,您可能会看到类似的错误

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

我在API下检查了我的google开发者控制台,查看与API键/auth键相关的项目,例如,
https://console.developers.google.com/project//apiui/api
。Google+API的状态设置为关闭。我把它打开了

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

“未配置访问权限。请使用Google开发者控制台激活项目的API。”


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

当您已经登录并且仍在反复尝试登录时,会发生此问题。我也面临同样的错误,所以做了一些实验1)我在手机上打开了网站,一切都很好。2) 然后我试着用另一台笔记本电脑,用不同的gmail帐号登录,结果还是很好。3) 在我的第一台笔记本电脑上,我再次点击“登录”按钮,我得到了同样的错误,所以我打开google.com,然后完全注销,然后再试一次,这次成功了。所以我相信,问题是,点击登录按钮一次又一次,而不注销

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

干杯

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

如果没有它,您将出现如下错误:

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

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
requires signup."
 }
}
1) 打开

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


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

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

下面是通过jQuery实现的方法:

    $.ajax({
      type: "GET", 
      url: "https://www.googleapis.com/plus/v1/people/me",
      headers: {
       "Authorization":"Bearer " + {access_token},
      }
    });
似乎您的问题在于服务器端代码,在该代码中,您在参数中传递了access_令牌(这是不必要的)

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

您必须添加带有URL的
apiKey

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

我也遇到了同样的问题,解决办法是:设置APIKEY,我也很绝望,最后我设法找到了解决办法。唯一的问题是添加正确的api令牌链接到你的应用程序,在我的例子中是浏览器令牌,并且一切正常

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

{calendar\u id}/events?&key={api\u key}

也许我会帮助有同样问题的人


祝你好运

在我的情况下,它发生在一天中的某个特定时间,在花了几个小时后,终于发现我的每日配额限制(每100秒查询次数)在当时被超过了,因为请求数量很多。所以它抛出了错误。我已经联系了谷歌支持部门以增加它们。

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


我试图使用
access\u token
获取返回的用户名和图片,而他们在上一次会话中已经登录。在运行到
“unauthenticated use”
错误消息之后,这就是最终通过PHP中的cURL实现的功能

//initialize provider specific params for oauth2
$access_token = <fetched from app database from last login> //remember to never expose this to users
$api_url = 'https://www.googleapis.com/plus/v1/people/me';
$headers = [
    'Authorization: Bearer '.$access_token
];

//send curl request
$curl = curl_init();
$curl_opts = [
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POST => 0, //GET
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => 1,
    CURLOPT_SSL_VERIFYHOST => 2,
    CURLOPT_URL => $api_url,
    CURLOPT_HTTPHEADER => $headers,
];
curl_setopt_array($curl, $curl_opts);
$curl_response = json_decode(curl_exec($curl), true);
$curl_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

//parse curl response from provider into name and icon fields for my app
$name = $curl_response['displayName'];
$icon = $curl_response['image']['url'];
//初始化oauth2的特定于提供程序的参数
$access\u token=//记住永远不要向用户公开此内容
$api\u url='1https://www.googleapis.com/plus/v1/people/me';
$headers=[
'授权:承载'.$access\u令牌
];
//发送卷曲请求
$curl=curl_init();
$curl_opts=[
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_POST=>0,//获取
CULLOPT_超时=>30,
CURLOPT_SSL_VERIFYPEER=>1,
CURLOPT_SSL_VERIFYHOST=>2,
CURLOPT_URL=>$api_URL,
CURLOPT_HTTPHEADER=>$headers,
];
curl_setopt_数组($curl,$curl_opts);
$curl\u response=json\u decode(curl\u exec($curl),true);
$curl\u status=curl\u getinfo($curl,CURLINFO\u HTTP\u代码);
//将提供者的curl响应解析为我的应用程序的名称和图标字段
$name=$curl_响应['displayName'];
$icon=$curl_response['image']['url'];
请注意
https://www.googleapis.
async function initClient () {
  return new Promise((resolve, reject) => {
    const API_KEY = "YOUR_GOOGLE_API_KEY"
    const CLIENT_ID = "YOUR_GOOGLE_OAUTH2_CLIENT_ID"
    const DISCOVERY_DOCS = ['https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest']
    const SCOPES = 'https://www.googleapis.com/auth/youtube.readonly'

    const initData = { apiKey: API_KEY, clientId: CLIENT_ID, discoveryDocs: DISCOVERY_DOCS, scope: SCOPES }

    gapi.client.init(initData).then(function () {
        // YOUR CODE HERE
    }, function (error) {
      reject(new Error('Reject Error: ' + error))
    })
      .catch(err => console.log('Catch Error', err))
  })
}
{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
requires signup."
 }
}
private val SCOPES: List<String> = arrayListOf(DriveScopes.DRIVE_FILE, DriveScopes.DRIVE_APPDATA, DriveScopes.DRIVE)
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}
service.events().patch(calendarId='primary', eventId=id, sendNotifications=True, body=update).execute()
    update = {
        'start': {
            'dateTime': time_start,  # Specifically this variable (time_start) was changed
            'timeZone': time_zone,
        },
        'end': {
            'dateTime': time_end,
            'timeZone': time_zone,
        },
        'description': description,
    }