无法在JavaScript中实现OAuth

时间:2015-11-18 12:41:33

标签: javascript html cordova oauth

我通过玩PhoneGap(HTML,CSS,JavaScript)来玩App Development。我试图通过OAuth.io实现Instagram身份验证。这是我的代码:

HTML:

<!DOCTYPE html> 
<html>
<head>
  <title>X</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
  <link rel="stylesheet" href="lib/jquery.mobile-1.4.5.min.css" />
  <link rel="stylesheet" type="text/css" href="css/index.css" />

</head>

<body>

<div data-role="page" id="pageone" class="pagewrapper">
    <div data-role="panel" id="rightpanel" data-position="right">

        <p>hej</p>
    </div>

    <div data-role="panel" id="leftpanel" data-position="left">

        <p>hej</p>
    </div>
    <div data-role='header' id="header" data-id='pheader' data-position='fixed' data-transition='none'>
            <span id="right-menu-toggle"><a href="#rightpanel"><img src="img/menu-toggle.png" width="25px" height="25px"/></a></span>
            <span id="left-menu-toggle"><a href="#leftpanel"><img src="img/settings-toggle.png" width="25px" height="25px"/></a></span>
    </div>


    <div role="main" class="ui-content">
        <button type="bytton" onclick="oAuthfct()">Instagram!</button>
        <p id="test">hej</p>
    </div>




</div>

<script src="cordova.js"></script>
<script src="../plugins/com.oauthio.plugins.oauthio/www/oauth.js"></script> 
<script src="lib/jquery-2.1.1.min.js"></script>
<script src="js/app.js"></script>
<script src="lib/jquery.mobile-1.4.5.min.js"></script>

</body>
</html>

JavaScript的:

function oAuthfct() {
    document.getElementById("test").innerHTML = "Paragraph changed!";
    OAuth.initialize('utBjpWgXLntpPoz3t2Tg_9pzOLB');
    OAuth.popup('instagram', function(error, success){
  // See the result below
});
}

段落正在改变,所以我确定我的JavaScript文件已加载。但没有其他事情发生。我正在PhoneGap Developer模拟器中测试它。

我也试过在Firefox中测试它,我得到以下错误:

  

ReferenceError:模块未定义module.exports = {oauth.js   (第76行,第1栏)

     

ReferenceError:未定义OAuth   OAuth.initialize( 'utIjrESXUntpPfz5t2tg_3pzODM'); app.js(第26行,col   2)

1 个答案:

答案 0 :(得分:0)

您是否尝试添加&#39; OAuth&#39;作为您的应用模块中的依赖项?

.controller('LoginController', ['OAuth',function(OAuth)
...
]