【发布时间】:2014-01-14 03:19:36
【问题描述】:
我正在尝试像这样使用 Google plus API(通过 googie-api-javascript)实现(省略完整代码):
var clientId = '7454475891XxxxxxXom4c6n.apps.googleusercontent.com'; //fake client
var apiKey = '-uTH_p6NokbrXXXXXXXXXXXXX'; //Fake Key
var scopes = 'https://www.googleapis.com/auth/plus.me';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}
function handleAuthResult(authResult) {
if (authResult && !authResult.error) {
makeApiCall();
} else {
//handle user-approval
}
}
// Load the API and make an API call. Display the results on the screen.
function makeApiCall() {
gapi.client.load('plus', 'v1', function() {
var o = gapi.client.plus;
alert(o);
});
}
代码在 gapi.client.load 之前运行良好(包括允许访问的用户) - 此回调被调用但 alert(o) 将返回未定义。
在检查 HTTP 请求时,我看到 .load 发出一个请求:
https://content.googleapis.com/discovery/v1/apis/plus/v1/rpc?fields=methods%2F*%2Fid&pp=0&key=-uTH_p6NokbrXXXXXXXX
这将返回带有以下消息的 HTTP 400:
{"error":{"errors":[{"domain":"usageLimits","reason":"keyInvalid","message":"Bad Request"}],"code":400,"message":"Bad Request"}}
我的问题是 - 我需要进行哪些更改才能使其正常工作? 我需要启用一些秘密设置吗? Google+ 在 API 列表下的 google-developer-console 中启用。
感谢您的帮助, 阿隆
【问题讨论】:
标签: javascript oauth-2.0 google-plus