注册

android端集成im即时通讯,登录注册失败,208失败码code,有没有大佬帮忙解决一下

D/ONE SDK: [2023/04/21 17:20:42:870]: [EMARHttpAPI] httpExecute code: 401
D/ONE SDK: [2023/04/21 17:20:42:870]: performWithMethod requestTimeSpent: 109
[2023/04/21 17:20:42:870]: performWithMethod mErrorDesc: {"error":"unauthorized","exception":"EasemobSecurityException","timestamp":1682068843783,"duration":0,"error_description":"Open registration doesn't allow, so register user need token,"}
W/System.err: java.lang.Exception: Toast callstack! strTip=注册失败!208
然后还有一个url点进去是这个:{"exception":"com.easemob.im.exceptions.EasemobSecurityException","duration":0,"error":"unauthorized","error_description":"Unable to authenticate (OAuth)","timestamp":1682069129309}
已邀请:
package com.example.myapplication8;

import androidx.appcompat.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.hyphenate.chat.EMClient;
import com.hyphenate.exceptions.HyphenateException;

public class RegistActivity extends AppCompatActivity implements View.OnClickListener {

private EditText register_username;
private EditText register_password;
private EditText register_confirm_password;
private Button register_submit;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regist);
initView();
}

private void initView() {
register_username = findViewById(R.id.register_username);
register_password = findViewById(R.id.register_password);
register_confirm_password = findViewById(R.id.register_confirm_password);
register_submit = findViewById(R.id.register_submit);
register_submit.setOnClickListener(this);
}

@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.register_submit:
StartRegister();
break;
default:
break;
}
}

//点击注册
private void StartRegister() {
String string_username = register_username.getText().toString().trim();
String string_password = register_password.getText().toString().trim();
String string_confirm_password = register_confirm_password.getText().toString().trim();

Log.d("TAG", "StartRegister: "+ValidUtil.isValidUserName(string_username)+
ValidUtil.isValidPassWord(string_password));
if (ValidUtil.isValidUserName(string_username)){
if (ValidUtil.isValidPassWord(string_password)){
if (ValidUtil.isValidPassWord(string_confirm_password)&&string_password.equals(string_confirm_password)){
// 注册失败会抛出 HyphenateException
// 同步方法,会阻塞当前线程。
new Thread(new Runnable() {
@Override
public void run() {
try {
EMClient.getInstance().createAccount(string_username, string_password);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(RegistActivity.this, "注册成功!", Toast.LENGTH_SHORT).show();
finish();

}
});
} catch (HyphenateException e) {
e.printStackTrace();
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(RegistActivity.this, "注册失败!"+e.getErrorCode(), Toast.LENGTH_SHORT).show();
}
});
}
}
}).start();
}
}else {
Toast.makeText(this, ValidUtil.TOAST_ERROR_PASSWORD, Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(this, ValidUtil.Toast_ERROR_USERNAME, Toast.LENGTH_SHORT).show();
}
}



}

好像是创建应用时选择开放注册就可以解决

要回复问题请先登录注册