2014-02-11 34 views
1

當我嘗試通過使用其他端口的另一個站點使用Google Calendar API時,我收到錯誤origin_mismatch消息。錯誤:使用Google日曆API和端口444時的origin_mismatch

當從http://original.domain.edu發送API請求時,代碼不會返回錯誤。

但是,當代碼從https://original.domain.edu:444(這是應用程序使用的安全登錄端口)發送API請求時,代碼會返回上述標題錯誤。

我在我的API控制檯中向我的OAuth客戶端添加了https://original.domain.edu:444https://original.domain.edu,但同樣的錯誤仍在發生。有人可以提供一些幫助嗎?

var exportCalendarToGoogle = function() { 

var clientId = 'XXXXXXXXXXXXXXXXXXXXXXXXX'; 
var scope = 'https://www.googleapis.com/auth/calendar'; 
var apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXX'; 

var withGApi = function() { 
    console.log("gapi loaded"); 
    setTimeout(function() { 
     gapi.client.setApiKey(apiKey); 
     gapi.auth.init(checkAuth); 
    }, 500); 
} 

var checkAuth = function() { 
    gapi.auth.authorize({client_id: clientId, scope: scope, immediate: false}, handleAuthResult); 
} 

var handleAuthResult = function(authResult) { 
    if(authResult) { 
     gapi.client.load("calendar", "v3", exportCalendar); 
    } else { 
     alert("Authentication failed: please enter correct login information."); 
    } 
} 
... 
+0

你的來歷不匹配。一個允許的來源將會與另一個不同的方案(http與https)和/或端口(80 vs 444)不匹配,請按照使用的原則準確添加您的允許來源。 – soulseekah

回答

1

您需要一個服務器端文件充當代理/橋樑來解決JS Origin問題。

如:var scope = "https://original.domain.edu:444/proxy.php";

<?php 
//proxy.php file 
echo file_get_contents('https://www.googleapis.com/auth/calendar?' . http_build_query($_GET)); 
?> 
+0

對不起會給你賞金,但沒有檢查答案,直到我得到一個過期的通知。 –

相關問題