Google+ API “400 (Bad Request)” and “Refused to display … in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.” errors

谁说胖子不能爱 提交于 2019-11-28 03:45:59

问题


I am trying to integrate the G+ API with my website and am having a problem. If you look at the console when loading the page, you will see the following errors:

GET https://accounts.google.com/o/oauth2/postmessageRelay?parent=http%3A%2F%2Fwww.pricewombat.com 400 (Bad Request) cb=gapi.loaded_0:436

Refused to display 'https://accounts.google.com/o/oauth2/postmessageRelay?parent=http%3A%2F%2Fwww.pricewombat.com#rpctoken=356505585&forcesecure=1' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

I'm just using the example code given on Google's website:

<script type="text/javascript">
    (function() {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/client:plusone.js?onload=googlePlusOnloadCallback';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
</script>

If I run gapi.auth.signIn() in the console, nothing happens. I'm assuming the problem is related to the above errors when the page loads.

What's causing this problem and how do I fix it?

UPDATE:

I created a blank page on my website with this barebones code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>

<script type="text/javascript">
    (function() {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'http://apis.google.com/js/client:plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();
</script>
</body>
</html>

I tried loading the above page with and without the authentication meta tags (not shown above) and am still getting the errors.

It seems like this has to be a problem on Google's end since I'm just using the most basic barebones example code and it's not working.


回答1:


Well, apparently Google+ just had a brainfart or something, because the solution was simply to clear my cookies!

I tried using my website on another computer and the Google+ API worked fine (no errors), so I tried clearing the cookies on my desktop and lo and behold, it started working!




回答2:


What I found out was that if the client has opened up the chrome for very long time, they would get this error. Once they close the chrome and reopen, they don't have any trouble with the issue. My solution was to download the script from the server, uploaded it to our server and made it as a backup download.



来源:https://stackoverflow.com/questions/24681594/google-api-400-bad-request-and-refused-to-display-in-a-frame-because-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!