Search code examples
javascriptgoogle-analyticsyoutubeyoutube-apigoogle-oauth

Google OAuth2 Origin Mismatch


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!


Solution

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