gpt4 book ai didi

javascript - 处理多个 Gmail 帐户

转载 作者:行者123 更新时间:2023-12-02 23:46:42 25 4
gpt4 key购买 nike

我正在使用 Google Calendar JavaScript API。它对于单个帐户工作正常。问题是当用户登录到我的两个 Gmail 帐户时,它每次都会要求用户选择用户想要使用的帐户。

我希望 API 至少在 session 中记住我的最后一个选择,或者最好是在用户断开连接之前记住我的最后选择。

这是我的 JS 文件。

var clientId = $("#CalendarClientId").val();


var scopes = 'https://www.googleapis.com/auth/calendar';
var objEventList = [];
var calendarIdAtt;

function InitilizeCalendarAPI() {
// Step 2: Reference the API key
window.setTimeout(checkAuth, 5);
}
function CheckGoogleCalAuth() {

gapi.auth.authorize({ client_id: clientId, scope: scopes }, HandleAuthCallBack);
}
function checkAuth() {
gapi.auth.authorize({ client_id: clientId, scope: scopes }, HandelCalAuthResult);
}
function CheckAuthentication() {
gapi.auth.checkSessionState({ client_id: clientId }, CheckAuthCallback);
}
function CheckAuthCallback(loginDataCallback) {

if (loginDataCallback == false) {

checkAuth();
$("#googleAuthorize-Button").hide();
}
}
function HandelCalAuthResult(authResult) {
if (authResult && !authResult.error) {
/*authorizeButton.style.visibility = 'hidden';*/
$("#googleAuthorize-Button").hide();
if ($("#googleConnected").length > 0) {
$("#googleConnected").show();
}
/*bind listing of google calendar name in addevent page*/
if ($("#divGoogleCalendarNameList").length > 0) {
GetListOfCalendarNameFromGoogle();
}
} else {
$("#googleAuthorize-Button").show();
/*authorizeButton.style.visibility = '';*/
if ($("#googleConnected").length > 0) {
$("#googleConnected").hide();
}
}
if ($('#googleAuthorized-Button').length > 0) {
$("#googleAuthorize-Button").hide();
$('#googleAuthorized-Button').show();
$('#calenderSettingIcon').attr('data-original-title', 'Connected To Google');
}
}

function CheckAutheForEventList() {

gapi.auth.checkSessionState({ client_id: clientId }, CheckAuthCallbackListEvent);
}

function CheckAuthCallbackListEvent(loginDataCallback)
{
gapi.auth.authorize({ client_id: clientId, scope: scopes }, LoadEventListinAPI);
}

function checkAuthEventList() {
ConfirmConnectionToGoogleCalendar(function (isConnect) {
if (isConnect) {
gapi.auth.authorize({ client_id: clientId, scope: scopes }, LoadEventListinAPI);
}
});
}

function LoadEventListinAPI() {

gapi.client.load('calendar', 'v3', GetAllCalendar);
}

function GetAllCalendar() {
gapi.client.load('calendar', 'v3', GetCalendarAndTheirEvents);
}

function GetCalendarAndTheirEvents() {

objEventList = [];
try {
var objDate = GetMinAndMaxDate();
var finalMinDate = (objDate.MinDate).toISOString();;
var finalMaxDate = (objDate.MaxDate).toISOString();;

var request = gapi.client.calendar.calendarList.list();
var tempCount = 0;
request.execute(function (resp) {

var calLength = resp.items.length;
$.each(resp.items, function (index, item) {
if (item.accessRole == "owner") {
try {
calendarIdAtt = item.id;
var request = gapi.client.calendar.events.list({
'calendarId': item.id,
'showDeleted': false,
'singleEvents': true,
'orderBy': 'startTime',
'maxResults': 100,
'timeMin': finalMinDate,
'timeMax': finalMaxDate
});

request.execute(function (resp) {
tempCount = tempCount + 1;
var events = resp.items;
if (events.length > 0) {
objEventList.push(events);
}
if (tempCount == calLength) {
//Binding Kendo Scheduler with Google Calenda Events
var eventsList = BindEventToCalendar();
LoadEventsScheduler(eventsList);
}
});
}
catch (error) {
tempCount = tempCount + 1;
if (tempCount == calLength) {
BindEventToCalendar();
}
}
}
else {
tempCount = tempCount + 1;
if (tempCount == calLength) {
BindEventToCalendar();
}
}
});
});
return objEventList;
}
catch (exception) {
BindEventToCalendar();
return null;
}
}

//Function will display google calendar events in the Kendo Scheduler
function LoadEventsScheduler(eventsList) {

//This will retrun all the google calendar events to the server side for the scheduler
var request = {
EventsList: eventsList, CalendarAccount: calendarIdAtt
};
$.ajax({
type: "POST",
data: JSON.stringify(request),
url: $_SetEventScheduler,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var data;
if (msg.hasOwnProperty("d")) {
data = msg.d;
}
else
data = msg;
if (data.success) {
$("#scheduler").data("kendoScheduler").dataSource.read();
}
else {

}
}
});
}

我注意到 API 显示我已登录,但在多个帐户的情况下不会存储日历,因此它会再次要求我选择帐户。

摘要:我想保存完整的场景(可能是calendar_id或任何唯一标识符),它可以告诉API应该选择哪个帐户和哪个日历。

如果您需要更多详细信息,请告诉我。

最佳答案

我只是使用了 auth2 实现,它工作得很好。基本上当前的 session 状态功能在旧 API 中无法正常工作。这就是为什么它每次都要求选择帐户和日历。

关于javascript - 处理多个 Gmail 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55829455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com