[英]OAuth Google Analytics Client API javascript
I'm trying to connect the Google client API to display Google Analytics Data on my website. 我正在尝试连接Google客户端API以在我的网站上显示Google Analytics(分析)数据。
So i use this tutorial to try to connect the client API : https://developers.google.com/api-client-library/javascript/start/start-js 因此,我使用本教程尝试连接客户端API: https : //developers.google.com/api-client-library/javascript/start/start-js
i followed all the instructions, i made a OAuth Client on Google Developper Console. 我按照所有说明进行操作,我在Google Developper Console上创建了OAuth客户端。
here my code : 这是我的代码:
<button id="authorize-button">Authorize</button>
<script type="text/javascript">
var clientId = 'XXXXXXXXX';
var apiKey = 'XXXXXXX';
var scopes = 'https://www.googleapis.com/auth/plus.me';
function handleClientLoad() {
// Step 2: Reference the API key
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult && !authResult.error) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
// Step 3: get authorization to use private data
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
// Load the API and make an API call. Display the results on the screen.
function makeApiCall() {
// Step 4: Load the Google+ API
gapi.client.load('plus', 'v1').then(function() {
// Step 5: Assemble the API request
var request = gapi.client.plus.people.get({
'userId': 'me'
});
// Step 6: Execute the API request
request.then(function(resp) {
var heading = document.createElement('h4');
var image = document.createElement('img');
image.src = resp.result.image.url;
heading.appendChild(image);
heading.appendChild(document.createTextNode(resp.result.displayName));
document.getElementById('content').appendChild(heading);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
});
}
</script>
// Step 1: Load JavaScript client library
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
but it dont work, and i have no idea of what is the problem, i get this error : 但它不起作用,而且我不知道问题出在哪里,我得到了这个错误:
401. That’s an error.
Error: invalid_client
The OAuth client was not found.
Request Details
immediate=false
response_type=token
scope=https://www.googleapis.com/auth/plus.me
redirect_uri=postmessage
proxy=oauth2relay509775948
state=658721539|0.1255556678
origin=http://localhost
include_granted_scopes=true
client_id='MY SECRED KEY'
authuser=0
That’s all we know.
If anyone have a solution, it should be very nice ;) thanks in advance. 如果有人有解决方案,那就应该很好;)预先感谢。
i was in the wrong way, to display content from GAI , i need to use the Hello analytics tutorial, with PHP code. 我以错误的方式显示GAI的内容,我需要使用带有PHP代码的Hello Analytics教程。 https://developers.google.com/analytics/solutions/articles/hello-analytics-api?hl=fr#auth
https://developers.google.com/analytics/solutions/articles/hello-analytics-api?hl=fr#auth
apparently the documentation is outdated. 显然文档已经过时了。
thanks... 谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.