我不想对 google calander 进行简单的事件插入。
这是我的代码:
var gapi = window.gapi;
var CLIENT_ID = 'XXXXX';
var API_KEY = 'XXXXX';
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: CLIENT_ID});
});
// the auth part
gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events"})
.then(function() {
console.log("Sign-in successful");
// then Load the client
gapi.client.setApiKey(API_KEY);
gapi.client.load("https://content.googleapis.com/discovery/v1/apis/calendar/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
},
function(err) { console.error("Error signing in", err); });
// then insert event
var event = {
'summary': 'Awesome Event!',
'location': '800 Howard St., San Francisco, CA 94103',
'description': 'Really great refreshments',
'start': {
'dateTime': '2021-02-19T09:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'end': {
'dateTime': '2021-02-19T17:00:00-07:00',
'timeZone': 'America/Los_Angeles'
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'lpage@example.com'},
{'email': 'sbrin@example.com'}
],
'reminders': {
'useDefault': false,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10}
]
}
}
console.log("[client] ", gapi.client);
console.log("[calendar] ", gapi.client.calendar);
console.log("[events] ", gapi.client.calendar.events);
gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event,
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
第一次运行时出现错误:
"Not a valid origin for the client: http://localhost:8000 has not been whitelisted for client ID XXX. Please go to https://console.developers.google.com/ and whitelist this origin for your project's client ID."
我第二次运行它时,它确实打开了 OAuth 窗口,但我得到了:
"popup_closed_by_user"
这是在我将 http://localhost:8000 添加到我的 Authorized JavaScript origins
和 Authorized redirect URIs
之后。
它对 em 来说是超级有线的,我不明白什么是响铃。
我尝试清除饼干和现金,但没有帮助。 我来这里做什么?