Google+分享API中出现origin_mismatch错误

use*_*124 23 api share mismatch google-plus

我想在谷歌+上分享一些动态内容.为此,我检查了它https://developers.google.com/+/web/share/interactive#rendering_the_button_with_javascript

<head>
<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';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
 })();
</script>
</head>
<body>
<button
  class="g-interactivepost"
  data-contenturl="http://www.pubandbar-network.co.uk/" 
  data-clientid="102180630313.apps.googleusercontent.com"
  data-cookiepolicy="single_host_origin">  Share 
</button>
</body>
Run Code Online (Sandbox Code Playgroud)

但是在执行时我收到了这个错误

Error: origin_mismatch
Request Details

    scope=https://www.googleapis.com/auth/plus.login
    response_type=code token id_token gsession
    access_type=online
    redirect_uri=postmessage
    cookie_policy=single_host_origin
    proxy=oauth2relay554026710
    origin=http://www.pubandbar-network.co.uk
    state=1995523240|0.4607792083184853
    display=page
    client_id=102180630313.apps.googleusercontent.com
    authuser=0
Run Code Online (Sandbox Code Playgroud)

请建议如何解决这个问题

Lee*_*Lee 46

原因不匹配通常是由于API项目控制台中未正确设置Javascript原点引起的.您需要确保Javascript来源与您的请求所来自的域匹配,并在登录后返回给用户.

有关详细信息,请参阅"创建客户端ID和客户端密钥"部分中的开发人员文档.

注意:这里常见的错误是为http://添加javascript原点而不是https://(反之亦然).如果您想允许用户从两者访问您的站点,则需要在javascript控制台中列出这两者.

注意(感谢Bethel Goka):如果用户访问您的站点时URL中显示端口号,则必须在javascript源中包含服务器的端口号.

  • 到目前为止谷歌文档没有更新,当我从原始URL删除www,然后只有它工作,http://example.com,"注册的应用程序"仍然没有,因为其他选项可以在"凭据"中找到 (2认同)

小智 8

删除"www"对我有用.来自谷歌控制台.我只是使用http://example.com而且它有效...


Yul*_*mok 5

对于VS用户:
打开项目的属性并获取项目URL:

在此输入图像描述
这是您的Javascript起源

更改以及重定向URI.应该是你的起源+"/ oauth2callback"
对我来说:

在此输入图像描述