package com.example.sll_user.chatapp;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.quickblox.auth.session.QBSettings;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
public class MainActivity extends AppCompatActivity {
//Quickblox Setting
static final String APP_ID = "73099";
static final String AUTH_KEY = "ggDWyCnN58b4LqQ";
static final String AUTH_SECRET = "RxQF2nzTUXXG3Fy";
static final String ACCOUNT_KEY = "fmZ9_c2WJLxryLp6izsx";
Button btnLogin,btnSignup;
EditText edtUser,edtPassword;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeframework();
btnLogin = (Button)findViewById(R.id.main_btnLogin);
btnSignup = (Button)findViewById(R.id.main_btnSignup);
edtUser = (EditText)findViewById(R.id.main_editLogin);
edtPassword = (EditText)findViewById(R.id.main_editPassword);
btnSignup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,SignUpActivity.class));
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = edtUser.getText().toString();
String password = edtPassword.getText().toString();
final QBUser qbUser = new QBUser(user, password);
QBUsers.signIn(qbUser).performAsync( new QBEntityCallback<QBUser>() {
@Override
public void onSuccess(QBUser qbUser, Bundle args) {
// success
}
@Override
public void onError(QBResponseException error) {
// error
Toast.makeText(getBaseContext(),""+ error.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
});
}
private void initializeframework(){
QBSettings.getInstance().init(getApplicationContext(),APP_ID,AUTH_KEY,AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
}
}
package com.example.sll_user.chatapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.quickblox.auth.QBAuth;
import com.quickblox.auth.session.QBSession;
import com.quickblox.auth.session.QBSettings;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
public class SignUpActivity extends AppCompatActivity {
//Quickblox Setting
static final String APP_ID = "73099";
static final String AUTH_KEY = "ggDWyCnN58b4LqQ";
static final String AUTH_SECRET = "RxQF2nzTUXXG3Fy";
static final String ACCOUNT_KEY = "fmZ9_c2WJLxryLp6izsx";
Button btnSignUp, btnCancel;
EditText edtUser, edtPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
QBSettings.getInstance().init(getApplicationContext(),APP_ID,AUTH_KEY,AUTH_SECRET);
QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
registerSession();
btnSignUp = (Button)findViewById(R.id.signup_btnSignUp);
btnCancel = (Button)findViewById(R.id.signup_btnCancel);
edtUser = (EditText)findViewById(R.id.signup_editLogin);
edtPassword = (EditText)findViewById(R.id.signup_editPassword);
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user = edtUser.getText().toString();
String password = edtPassword.getText().toString();
final QBUser qbUser = new QBUser (user,password);
QBUsers.signUp(qbUser).performAsync(new QBEntityCallback<QBUser>() {
@Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
Toast.makeText(getBaseContext(),"Sign Up Successfully",Toast.LENGTH_SHORT).show();
finish();
}
@Override
public void onError(QBResponseException e) {
Toast.makeText(getBaseContext(),""+e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
});
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
private void registerSession() {
QBAuth.createSession().performAsync(new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(QBSession qbSession, Bundle bundle) {
}
@Override
public void onError(QBResponseException e) {
Log.e("Error",e.getMessage());
}
});
}
}
08-22 14:41:51.095 8853-8877/com.example.sll_user.chatapp D/EGL_emulation: eglMakeCurrent: 0xf10638c0: ver 3 0 (tinfo 0xf0fb1d90)
08-22 14:41:52.941 8853-8877/com.example.sll_user.chatapp D/EGL_emulation: eglMakeCurrent: 0xf10638c0: ver 3 0 (tinfo 0xf0fb1d90)
08-22 14:42:00.091 8853-8853/com.example.sll_user.chatapp D/QBASDK: =========================================================
=== REQUEST ==== 90d50467-906e-4bf4-b385-f4c8b77d2d21 ===
REQUEST
POST https://api.quickblox.com/login.json
HEADERS
QuickBlox-REST-API-Version=0.1.1
QB-SDK=Android 3.3.0
QB-Token=1fd1a31114b5e8fc0ec390e7a1eff83ac3011d8b
PARAMETERS
login=
password=
INLINE
POST https://api.quickblox.com/login.json?login=&password=
08-22 14:42:01.043 8853-8853/com.example.sll_user.chatapp D/QBASDK: *********************************************************
*** RESPONSE *** 90d50467-906e-4bf4-b385-f4c8b77d2d21 ***
STATUS : 401
HEADERS
Status=401 Unauthorized
Server=nginx/1.8.1
Access-Control-Allow-Origin=*
X-Request-Id=bf9912db-42c2-41b6-95b0-31b126761da6
X-Content-Type-Options=nosniff
X-Runtime=0.008429
WWW-Authenticate=OAuth realm=users
Connection=Close
X-Android-Received-Millis=1534920121038
Date=Wed, 22 Aug 2018 06:41:56 GMT
QuickBlox-REST-API-Version=0.1.1
X-Frame-Options=SAMEORIGIN
X-Android-Selected-Protocol=http/1.1
Strict-Transport-Security=max-age=31536000
Cache-Control=no-cache
X-Android-Response-Source=NETWORK 401
Set-Cookie=_mkra_ctxt=ec0ec27a8d453e7d5183aaeda6fe5f21--401; path=/; max-age=5; HttpOnly; secure
X-Android-Sent-Millis=1534920120550
Content-Length=55
X-XSS-Protection=1; mode=block
Content-Type=application/json; charset=utf-8
BODY
'{"errors":{"base":["Required session does not exist"]}}'
08-22 14:42:01.120 8853-8877/com.example.sll_user.chatapp D/EGL_emulation: eglMakeCurrent: 0xf10638c0: ver 3 0 (tinfo 0xf0fb1d90)
08-22 14:42:03.053 8853-8877/com.example.sll_user.chatapp D/EGL_emulation: eglMakeCurrent: 0xf10638c0: ver 3 0 (tinfo 0xf0fb1d90)
最近,我尝试使用QuickBlox API构建singIn和signUp函数。但是,当我通过单击登录按钮发送请求时,我收到了一条错误消息(基本的必需会话不存在)。
我似乎没有创建会话来绕过QuickBlox令牌,但不是该功能
QBUsers.signIn(qbUser).performAsync( new QBEntityCallback<QBUser>(){}
已经是读写会话了吗?
有人可以帮我吗?谢谢