web javascript Google Play API OAuth 2.0访问
您好,我在从Google Play API加载数据时遇到问题。我试图从我的游戏(鲁尼入侵者)加载排行榜数据。我想在我的自定义网站上显示游戏统计。我尝试使用“GoogleAPI客户端库for JavaScript”来实现“授权”OAuth 2.0访问。 我使用了“授权”访问GoogleAPI的示例(使用OAuth2.0) Javascript代码:web javascript Google Play API OAuth 2.0访问,javascript,api,Javascript,Api,您好,我在从Google Play API加载数据时遇到问题。我试图从我的游戏(鲁尼入侵者)加载排行榜数据。我想在我的自定义网站上显示游戏统计。我尝试使用“GoogleAPI客户端库for JavaScript”来实现“授权”OAuth 2.0访问。 我使用了“授权”访问GoogleAPI的示例(使用OAuth2.0) Javascript代码: <script type="text/javascript"> function handleClientLoad() { gap
<script type="text/javascript">
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
function initClient() {
gapi.client.init({
//API key from google
apiKey: '***',
discoveryDocs: ["www.googleapis.com/discovery/v1/apis/games/v1/rest"],
//ClientID (for OAuth 2.0) from google develope console
clientId: '***',
scope: 'www.googleapis.com/auth/games'
}).then(function (data) {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
}, function (err) {
console.error('Our Error: ');
console.error(err);
});
}
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
makeApiCall();
}
}
function handleSignInClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
function handleSignOutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
function makeApiCall() {
// Make an API call to the People API, and print the user's given name.
console.log('api call');
return gapi.client.games.leaderboards.list()
.then(function(response) {
console.log(response);
}, function(reason) {
console.log(reason);
});
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
此外,初始化阶段(gapi.client.init())结束时没有任何错误
请帮我解决这个问题,或者告诉我我做错了什么?你确定你已经注册了,就像错误表明你没有注册一样?我确定您需要一个API密钥和一些用于授权的内容。我使用了我帐户的API manager凭据页()中正确的API密钥和ClientId。您使用的是服务帐户吗?然后它可能与一些更相关的讨论和讨论有关
{
"error": {
"errors": [
{
"domain": "global",
"reason": "UserRegistrationIncomplete",
"message": "User has not completed registration."
}
],
"code": 401,
"message": "User has not completed registration."
}
}