代码 -
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function(event) {
console.log('Event created: ' + event.htmlLink);
});
它给出了如下网址
我无法找到原因。这是我的api密钥或其他什么问题吗?
答案 0 :(得分:0)
糟糕!我很遗憾我找到了这个问题的解决方案。实际上我发送到日历的事件对象是错误的。现在它工作正常。这是我的一个愚蠢的错误。这是我的总代码,它对我来说工作正常.......
var CLIENT_ID = 'myClientId';
var SCOPES = ["https://www.googleapis.com/auth/calendar"];
var EvntJSn = '';
function addEventInGoogle(eventList){
EvntJSn = eventList;
var apiKey = 'myapikey';
gapi.client.setApiKey(apiKey);
gapi.auth.authorize(
{
'client_id': CLIENT_ID,
'scope': SCOPES.join(' '),
'immediate': true
}, handleAuthResult);
}
/**
* Handle response from authorization server.
*
* @param {Object} authResult Authorization result.
*/
function handleAuthResult(authResult){
if (authResult && !authResult.error) {
loadCalendarApi();
} else {
handleAuthClick(event);
}
}
/**
* Initiate auth flow in response to user clicking authorize button.
*
* @param {Event} event Button click event.
*/
function handleAuthClick(event) {
gapi.auth.authorize(
{
client_id: CLIENT_ID,
scope: SCOPES,
immediate: false
},
handleAuthResult);
return false;
}
function loadCalendarApi() {
gapi.client.load('calendar', 'v3', addEventToGglCalendar);
}
function addEventToGglCalendar(){
var event = EvntJSn;
var request = gapi.client.calendar.events.insert({
'calendarId': 'primary',
'resource': event
});
request.execute(function(event) {
console.log(event);
});
}