원산지 불일치 : http://googleappsdeveloper.blogspot.com/2011/12/using-new-js-library-to-unlock-power-of.htmlGoogle 캘린더 API 자바 스크립트 오류 : 내가 여기 간단한 자바 스크립트 코드에서 일하고 있어요
그것은 기본적으로 구글 캘린더에 인증을 획득하고 그 안에 포함 된 이벤트의 목록을 검색합니다. 웹 응용 프로그램을 등록하고 클라이언트 ID와 API 키를 받았습니다.
"오류 : 원본이 맞지 않습니다.", localhost를 사용하여 로컬로 javascript를 실행하고 있으며 localhost에 대한 Google 응용 프로그램 등록에서 내 홈페이지를 설정했습니다.
어떤 도움이라도 대단히 감사하겠습니다.
코드 :
<html>
<body>
<div id='content'>
<h1>Events</h1>
<ul id='events'></ul>
</div>
<a href='#' id='authorize-button' onclick='handleAuthClick();'>Login</a>
<script>
var clientId = '506979856128.apps.googleusercontent.com';
var apiKey = 'AIzaSyAGbQAZQU0YNL8hK5EU69exIg7_sOg3JoA';
var scopes = 'https://www.googleapis.com/auth/calendar';
function handleClientLoad() {
gapi.client.setApiKey(apiKey);
window.setTimeout(checkAuth,1);
checkAuth();
}
function checkAuth() {
gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeButton = document.getElementById('authorize-button');
if (authResult) {
authorizeButton.style.visibility = 'hidden';
makeApiCall();
} else {
authorizeButton.style.visibility = '';
authorizeButton.onclick = handleAuthClick;
}
}
function handleAuthClick(event) {
gapi.auth.authorize(
{client_id: clientId, scope: scopes, immediate: false},
handleAuthResult);
return false;
}
function makeApiCall() {
gapi.client.load('calendar', 'v3', function() {
var request = gapi.client.calendar.events.list({
'calendarId': 'primary'
});
request.execute(function(resp) {
for (var i = 0; i < resp.items.length; i++) {
var li = document.createElement('li');
li.appendChild(document.createTextNode(resp.items[i].summary));
document.getElementById('events').appendChild(li);
}
});
});
}
</script>
<script src="https://apis.google.com/js/client.js?onload=handleClientLoad"> </script>
</body>
</html>
소리가 합리적이지만 ... '''cd "/ Applications/Google 크롬 Canary.app/Contents/MacOS/"'''->'''./Google \ Chrome \ Canary --disable- 웹 보안''''''추적/BPT 트랩 : 5''' -'''Chrome이 예기치 않게 종료되었습니다 .'' –
Firefox에서 실행 ... 제대로 작동합니다. –
@CraigMorgan : chrome 확장 FF에서 ?? –