【问题标题】:Error: origin_mismatch when using Google calendar API with port 444错误:使用带有端口 444 的 Google 日历 API 时的 origin_mismatch
【发布时间】:2014-02-11 22:14:00
【问题描述】:

当我尝试通过另一个使用不同端口的站点使用 Google 日历 API 时,我收到一条错误 origin_mismatch 消息。

http://original.domain.edu发送API请求时,代码不会返回错误。

但是,当 API 请求从https://original.domain.edu:444(这是应用程序使用的安全登录端口)发送时,代码会返回上述标题错误。

我已在我的 API 控制台中将 https://original.domain.edu:444https://original.domain.edu 添加到我的 OAuth 客户端,但仍然发生相同的错误。有人可以提供一些帮助吗?

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.");
    }
}
...

【问题讨论】:

  • 您的出身不匹配。允许的来源将与不同的方案(http 与 https)和/或端口(80 与 444)不匹配,请完全按照使用的方式添加允许的来源。

标签: javascript api google-api google-calendar-api


【解决方案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) ); 
?>

【讨论】:

  • 很抱歉会给你赏金,但直到我收到过期通知才检查答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-01
  • 1970-01-01
  • 2021-08-17
  • 2018-08-28
  • 1970-01-01
  • 2013-10-17
  • 2015-06-16
相关资源
最近更新 更多