Google API를 사용하고 있습니다. (Hello Analytics 설명서를 참조하면됩니다.) 인증에 문제가 있습니다. 과정에서 나를 인증하지만 GA에서 데이터를 호출하려고하면이 액세스 권한으로 로그인해야한다는 오류 메시지가 표시됩니다. 인증 버튼이 없어서 인증 할 수 없으며 "세션 가져 오기"버튼이 나타나지만 오류가 발생합니다. 내 예제는 결과가 처리되는 지점까지 자습서 예제와 똑같아 보입니다. 왜 이것이 발생하는지 실제로 알지 못합니다. 어떤 도움을 주시면 감사하겠습니다. 다음은 내 코드입니다 (클라이언트 ID, API 키 및 GA 속성이 분명한 이유로 대체되었습니다).Google API 인증에 실패했습니다.
var clientId = 'clientid';
var apiKey = 'apikey';
var scopes = 'https://www.googleapis.com/auth/analytics.readonly';
function makeApiCall() {
var apiQuery = gapi.client.analytics.data.ga.get({
'ids': 'id',
'start-date': '2014-06-01',
'end-date': '2014-07-01',
'metrics': 'ga:pageviews',
'dimensions': 'ga:pagePath',
'filters': 'ga:pagepath=~marketplace/seller/(*.?)/example'
});
console.dir(apiQuery);
apiQuery.execute(handleCoreReportingResults);
}
// This function is called after the Client Library has finished loading
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) {
loadAnalyticsClient();
} else {
handleUnAuthorized();
}
}
// Authorized user
function handleAuthorized() {
var authorizeButton = document.getElementById('authorize-button');
var makeApiCallButton = document.getElementById('make-api-call-button');
makeApiCallButton.style.visibility = '';
authorizeButton.style.visibility = 'hidden';
makeApiCallButton.onclick = makeApiCall;
}
// Unauthorized user
function handleUnAuthorized() {
var authorizeButton = document.getElementById('authorize-button');
var makeApiCallButton = document.getElementById('make-api-call-button');
makeApiCallButton.style.visibility = 'hidden';
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
function handleAuthClick(event) {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
return false;
}
function loadAnalyticsClient() {
gapi.client.load('analytics', 'v3', handleAuthorized);
}
function handleCoreReportingResults(results) {
if (results.error) {
console.log('There was an error querying core reporting API: ' + results.message);
} else {
console.dir(results);
}
}
자습서 중 어떤 것이 있습니까? 링크를 게시하십시오. –
죄송합니다. https://developers.google.com/analytics/solutions/articles/hello-analytics-api – KRay