Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Plus API-密钥无效_Javascript_Api_Google Api_Google Plus_Google Plus One - Fatal编程技术网

Javascript Google Plus API-密钥无效

Javascript Google Plus API-密钥无效,javascript,api,google-api,google-plus,google-plus-one,Javascript,Api,Google Api,Google Plus,Google Plus One,我正在尝试使用javascript sdk进行oauth登录并访问google plus api。这里的代码基本相同: 在我的firebug控制台中,这是将api请求发送到以下地址的url: {key} 这是返回的错误: {“error”:{“errors”:[{“domain”:“usageLimits”,“reason”:“keyInvalid”,“message”:“Bad Request”}],“code”:400,“message”:“Bad Request”} 我有: 1.将Goog

我正在尝试使用javascript sdk进行oauth登录并访问google plus api。这里的代码基本相同:

在我的firebug控制台中,这是将api请求发送到以下地址的url: {key}

这是返回的错误: {“error”:{“errors”:[{“domain”:“usageLimits”,“reason”:“keyInvalid”,“message”:“Bad Request”}],“code”:400,“message”:“Bad Request”}

我有: 1.将Google Plus Api添加到我的项目中 2.已创建oauth凭据 3.设置我的同意屏幕


但是,我仍然收到错误。

原因是您在请求中定义了密钥。如发现API文档()中所述:

“API发现服务只提供不需要的公共方法 需要身份验证。此外,与您向 许多其他Google API,您对发现服务的请求 API不应包含API密钥。如果确实提供了密钥,则 请求将失败。此行为有助于确保您不会失败 在分发以下工具时意外泄漏API密钥: 基于谷歌API发现服务。”

因此,您可以通过完全从请求中删除密钥来解决问题

如果您使用Google的javascript客户端执行此操作,并且在加载其他API时发生错误,则必须首先取消设置密钥:

gapi.client.setApiKey( null );          
gapi.client.load( "plus", "v1", function( apiresponse ) { ... } );
如果其他函数稍后需要该键,则必须重新设置


为了避免不断地设置和取消设置密钥,我在身份验证之前加载所有需要的API,然后设置API密钥,这样就不再有问题了。

您在请求中实际看到的是什么?或者你用这个问题的钥匙替换了你的实际钥匙?我替换了这个问题的钥匙