Got origin_mismatch error in Google+ share api

2019-01-14 11:12发布

I want to share some dynamic content on google+. For this I checked it 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>

But when executing I am getting this error

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

Please suggest how to fix this

16条回答
戒情不戒烟
2楼-- · 2019-01-14 11:50

(The error has the answer for you)

need to set javascript origin in google console api As

origin=**http://www.pubandbar-network.co.uk**

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
查看更多
萌系小妹纸
3楼-- · 2019-01-14 11:51

It worked for me by removing "www." from google console. I simply used http://example.com and it worked ...

查看更多
甜甜的少女心
4楼-- · 2019-01-14 11:53

Just a little addition to Lee's answer: listing both the www.whatever.ext and whatever.ext forms of your URL in JavaScript origins may get rid of the error. That's what did the trick for my app.

查看更多
成全新的幸福
5楼-- · 2019-01-14 11:55

For VS users:
Open Properties of your project and get Project URL:

enter image description here
This is your Javascript Origins

Change also the Redirect URIs. It should be your origins + "/oauth2callback"
For me:

enter image description here

查看更多
何必那么认真
6楼-- · 2019-01-14 11:55

My default javascript origins is https://www , my website does not support https:// , I included http://www. http:// https://www. and https:// , it works.

查看更多
【Aperson】
7楼-- · 2019-01-14 11:55

I did a stupid thing which took a few minutes to resolve, so I thought I would post a warning in case somebody else falls in this trap.

In the console, when origins are displayed, 'Redirect URIs' come above 'Javascript origins'. When you open the edit pane, it's the other way around, so if you are not paying attention, you could paste your origins in the Redirect URIs field and ....

查看更多
登录 后发表回答