Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google联系人API和来源错误_Javascript_Jquery_Google Api_Google Console Developer - Fatal编程技术网

Javascript Google联系人API和来源错误

Javascript Google联系人API和来源错误,javascript,jquery,google-api,google-console-developer,Javascript,Jquery,Google Api,Google Console Developer,我使用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' hea

我使用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正文
数据类型中缺少的部分:“jsonp”

感谢@Mehmet

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

您是否在ajax请求中尝试了crossDomain:true和dataType:'jsonp'?将access_token=(您的token)添加到api请求中记住这是一个旧的gdata api,它可能不会返回xmljson@Mehmet数据类型:“jsonp”缺少一部分!谢谢。@Mehmet请添加您的评论,以便我可以接受。