gpt4 book ai didi

javascript - Google Contacts API 和来源错误

转载 作者:行者123 更新时间:2023-12-01 05:23:39 25 4
gpt4 key购买 nike

我使用 Google Contacts API 3.0 版,当我想调用其中一个地址以获取联系人列表中的请求数据时,发生了此错误:

XMLHttpRequest cannot load https://www.google.com/m8/feeds/contacts/XXXX@gmail.com/full. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://YYYY.ir' is therefore not allowed access. The response had HTTP status code 405.

这是我的代码:

function PopupFunc() {
jQuery("input[title*='GetgoogleButt1']")
.off()
.on('click', function (event) {
console.log('clicked');
var lnk = "https://accounts.google.com/o/oauth2/v2/auth?" +
//"scope=email profile&" +
"scope=https://www.googleapis.com/auth/contacts.readonly&" +
//"scope=https://www.googleapis.com/auth/user.phonenumbers.read&" +
"state=/profile&" +
"redirect_uri=http://XXXX/Mypagerdi.html&" +
"response_type=token&" +
"client_id=MUCLIENTID.apps.googleusercontent.com&" +
"output=embed";

var authTab = window.open(lnk, "Auth", "_blank, width=600, height=600");

jQuery(window).off().on("message", function (e) {
if ( e.originalEvent.origin == "http://XXXX/" ) {
console.log("message is : ", e.originalEvent.data)
var hashdic = e.originalEvent.data;
var authrz = hashdic["token_type"] + ' ' + hashdic["access_token"];
console.log(hashdic["expires_in"])
console.log(authrz)
if ( hashdic["#error"] == undefined ) {
jQuery.ajax({
url: "https://www.google.com/m8/feeds/contacts/YYYY@gmail.com/full",
headers: {
'Authorization': authrz,
'Content-Type': 'application/json'
},
method: 'GET',
success: function (data) {
console.log('succes: ' + data);
}
});
}
}
});
});
}
PopupFunc();

我在凭据中添加了授权 JavaScript 来源,但此错误仍然存​​在!

编辑:

这是ajax主体中缺少的部分dataType:'jsonp'感谢@Mehmet

最佳答案

请在您的 ajax 请求中尝试 crossDomain: true 和 dataType: 'jsonp'。

关于javascript - Google Contacts API 和来源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41346897/

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