【问题标题】:Can't implement OAuth in JavaScript无法在 JavaScript 中实现 OAuth
【发布时间】:2016-02-20 04:59:52
【问题描述】:

我通过玩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)

【问题讨论】:

    标签: javascript html cordova oauth


    【解决方案1】:

    您是否尝试在您的应用模块中添加“OAuth”作为依赖项?

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

    【讨论】:

    • 我不确定你的意思。我对 JavaScript 还很陌生,以前没有听说过这样的依赖关系。能详细说明一下吗?
    猜你喜欢
    • 2017-08-27
    • 1970-01-01
    • 2011-02-27
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多