简体   繁体   English

如何使用phonegap + quickblox注册/登录用户?

[英]How to sign up/login a user using phonegap + quickblox?

I have been been working on an app in phonegap, wanting to make calls to the quickblox backend service. 我一直在使用phonegap中的应用程序,想要调用quickblox后端服务。

The app successfully gets the app token and creates an API session but the user.create code fails - here is my code from index.html 该应用程序成功获取应用程序令牌并创建API会话但user.create代码失败 - 这是我的index.html代码

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title></title>
    <!--  -->
    <link rel="stylesheet" href="css/themes/.css" />
    <link rel="stylesheet" href="css/themes/jquery.mobile.icons.min.css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile.structure-1.4.3.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
    <script src="js/config.js"></script>
    <script src="js/quickblox.js"></script>
</head>
<body>
    <div style="width:100%;">
        <h1 style="text-align:center;">The Activity Network</h1>
    </div>
    <div>
        <div data-role="tabs" id="tabs">
            <div data-role="navbar">
                <ul>
                    <li><a href="#one" data-ajax="false">Login</a></li>
                    <li><a href="#two" data-ajax="false">Register</a></li>
                </ul>
            </div>
            <div id="one">
                <h2>Login</h2>
                <input type="text" id="new_login" placeholder="Username" />
                <input type="password" id="new_password" placeholder="Password" />
                <input id="auth" type="submit" value="Submit" onclick="window.location='sportsSelector.html'" />
            </div>
            <div id="two">
                <h2>Register</h2>
                <input type="text" id="login" placeholder="Username"/>
                <input type="email" id="email" placeholder="E-Mail Address"/>
                <input type="email" id="confirmEmail" placeholder="Confirm E-Mail Address"/>
                <input type="password" id="password" placeholder="************"/>
                <input type="password" value="confirmPassword" placeholder="************"/>
                <input id="register" type="submit" value="Submit" />
            </div>
        </div>
     </div>
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>

    <script src="scripts/index.js"></script>
    <script>
        $(document).ready(function () {
            QB.init(QBAPP.app_id, QBAPP.auth_key, QBAPP.auth_secret);
            //console.log(QBAPP.app_id, QBAPP.auth_key, QBAPP.auth_secret);
            QB.createSession(function (err, result) {
                console.log(result);
                // callback function
            });
        });

        var username;
        var password;
        var email;

        $('#register').click(function () {
            console.log("Ready! Getting the user details.");

            username = document.getElementById('login').value;
            password = document.getElementById('password').value;
            email = document.getElementById('email').value;

            console.log("Username: ", username);
            console.log("Password: ", password);
            console.log("E-Mail: ", email);

            var params, connection;

            params = {
                login: username,
                password: password,
                email: email
            };

            //console.log("Params: ", params);

            create(params);
        });

        function create(params) {
            console.log("Creating new user");
            QB.users.create(params, function (err, result) {
                console.log("Result: ", result);
                // callback function
            });
        }
    </script>
</body>
</html>

If anyone can spot what Im missing then I'd really appreciate it. 如果有人能发现我失踪的东西,那么我真的很感激。 Currently, it spits out the following in the console: 目前,它在控制台中吐出以下内容:

    XHR finished loading: POST "http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=https%3A//users.quickblox.com/users.json".
[DEBUG] Add new user: POST https://users.quickblox.com/users.json?user[owner_id]=&user[login]=Username&email[email]=undefined&user[password]=Password&token=undefined index.html:197

Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=https%3A//users.quickblox.com/users.json

I think one of your other scripts (local) might be interfering. 我认为你的其他一个脚本(本地)可能会干扰。 Copied your code to jsfiddle, added some dummy credentials and it worked just fine. 将您的代码复制到jsfiddle,添加了一些伪凭证,它工作得很好。

$(document).ready(function () {
    var QBAPP = {
        app_id: replace_with_yours,
        auth_key: replace_with_yours,
        auth_secret: replace_with_yours
    };

    QB.init(QBAPP.app_id, QBAPP.auth_key, QBAPP.auth_secret);

    QB.createSession(function (err, result) {
        console.log(result);
        // callback function
    });
});

var username;
var password;
var email;

$('#register').click(function () {
    console.log("Ready! Getting the user details.");

    username = document.getElementById('login').value;
    password = document.getElementById('password').value;
    email = document.getElementById('email').value;

    console.log("Username: ", username);
    console.log("Password: ", password);
    console.log("E-Mail: ", email);

    var params, connection;

    params = {
        login: username,
        password: password,
        email: email
    };

    create(params);
});

function create(params) {
    console.log("Creating new user");
    QB.users.create(params, function (err, result) {
        console.log("Result: ", result);
        // callback function
    });
}

Here is your request: 这是您的要求:

POST https://users.quickblox.com/users.json?user[owner_id]=1622883&user[login]=Username&email[email]=undefined&user[password]=Password&token=undefined

At least something wrong with email and token: 至少电子邮件和令牌有问题:

email[email]=undefined
token=undefined

try to check these parameters carefully 尝试仔细检查这些参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM