Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got origin_mismatch error in Google+ share api

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

like image 487
user2439124 Avatar asked May 31 '13 05:05

user2439124


4 Answers

Origin mismatch is normally caused by the Javascript origins not being set correctly in the API project console. You need to make sure that the Javascript origins match the domain from which your requests are coming and to which you are returning the user after sign in.

More details can be found in the developer documentation in the "Create a client ID and client secret" section.

Note: A common mistake here is to add javascript origins for http:// but not https:// (or vice versa). If you want to allow users to access your site from both then you need to list both in the javascript console.

Note (Thanks Bethel Goka): You must include the port number of your server in the javascript origins if a port number appears in the url when users access your site.

like image 132
Lee Avatar answered Nov 20 '22 20:11

Lee


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

like image 21
user3981671 Avatar answered Nov 20 '22 20:11

user3981671


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

like image 5
Yuliia Ashomok Avatar answered Nov 20 '22 20:11

Yuliia Ashomok


(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
like image 4
Yene Mulatu Avatar answered Nov 20 '22 20:11

Yene Mulatu