0

I want to use Google Youtube Analytics API. I know that we have to use Oauth2, so I get my client ID and then follow this instruction https://developers.google.com/youtube/analytics/v1/sample-application cause I use youtube analytics for my web app.

I get confused when my request get error response

Error: origin_mismatch enter image description here

enter image description here

I have checked my Authorized JavaScript origins, make sure that they are same. I also host my code.

EDIT just in case you wonder my code, here my index.php file

<html>
<head>

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="index.js"></script>
    <script type="text/javascript" src="//www.google.com/jsapi"></script>
    <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=onJSClientLoad"></script>

</head>
</body>

    <div id="login-container" class="pre-auth">This application requires access to your YouTube account.
        Please <a href="#" id="login-link">authorize</a> to continue.
    </div>
    <div class="post-auth">
        <div id="message"></div>
        <div id="chart"></div>
        <div>Choose a Video:</div>
        <ul id="video-list"></ul>
      </div>

<body>

` Did I do something wrong??? thanks in advance!

fajar ainul
  • 480
  • 2
  • 8
  • 27

2 Answers2

0

Make sure that the OAuth ClientId you're using matches with the URI Origin you've specified in your Google Dev Console. For example you have this Client ID 1234567890 for the URI origin http://www.mysimplesite.com in GDC, that ClientID will only work on that domain.

If you want that Client ID to work on http://www.myawesomesite.com as well, you'd have to add it on the list of URIs. If you use it in a domain not specified in "Authorised Javascript origins", you will have origin mismatch error. http://imgur.com/q2PJGCP

Note: Make sure you've enabled Youtube API as well.

For additional reference you may check this SO thread as well.

Community
  • 1
  • 1
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • thanks for your answer before. I have double checked my GDC and I have input **Authorize Javascript origins** correctly. I found my solution myself. Thnks – fajar ainul Oct 30 '16 at 02:10
0

I have found my solution myself. I just change immediate: true to immediate: false on checkAuth function. I dont know why, but it works.

fajar ainul
  • 480
  • 2
  • 8
  • 27