获取“$ XMPPErrorException:XMPPError:禁止 - 验证”创建MultiUserChat时出错 [英] Getting "$XMPPErrorException: XMPPError: forbidden - auth" error while creating MultiUserChat

查看:996
本文介绍了获取“$ XMPPErrorException:XMPPError:禁止 - 验证”创建MultiUserChat时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Smack Api(4.1.4)为XMPP创建了一个登录连接。现在我正在尝试使用

 尝试创建MultiUserChat尝试{
String myMUCName =TestGroup;
String myMUCService =conference(我的本地ip);
String myMUCfullName = myMUCName +@+ myMUCService;
String userName =Test5;

MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat muc = manager.getMultiUserChat(myMUCfullName);
muc.create(userName);

Log.d(LOCAL_TAG,createGroupChat - Group CEATED Successfully);
Form form = muc.getConfigurationForm();
表单submitForm = form.createAnswerForm();

列表< FormField> fields = form.getFields();
Log.d(LOCAL_TAG,createGroupChat - fields.size():+ fields.size()); (int i = 0; i< fields.size(); i ++){
FormField field =(FormField)fields.get(i);

if(!FormField.Type.hidden.equals(field.getType())&& field.getVariable()!= null){
submitForm.setDefaultAnswer(field.getVariable());
}
}

列表所有者=新的ArrayList();
owner.add(userName); //拥有用户
owner.add(Test7); //另一个用户

submitForm.setAnswer(muc#roomconfig_roomowners,业主);
submitForm.setAnswer(muc#roomconfig_publicroom,true);
submitForm.setAnswer(muc#roomconfig_persistentroom,true);
muc.sendConfigurationForm(new Form(DataForm.Type.submit));
//muc.sendConfigurationForm(submitForm);
Log.d(LOCAL_TAG,createGroupChat - 发送配置);
muc.join(TestGroup);
Log.d(LOCAL_TAG,createGroupChat - Group Joined Successfully - owners.size():+ owners.size());

但是,在创建组时,我收到了一个例外:

 org.jivesoftware.smack.XMPPException $ XMPPErrorException:XMPPError:perbidden  -  auth。 

希望如此,这个例外发生在代码

  muc.sendConfigurationForm(submitForm); 

这是为此而被评论的。因为我没有得到该代码之后的日志。为了解决这个问题,我把这个代码改成了

  muc.sendConfigurationForm(new Form(DataForm.Type.submit)); 

它修复了这个异常,并为我创建了一个组,因为我可以看到日志打印出来,可以看到我的小组在开火中。但是,通过这样做,我知道我所选择的用户群是如何添加的,因为所有者列表(或提交表单)不包括在任何地方。我不知道在这发生了什么,我不知道我在做正确。普茨建议我如何进行。谢谢提前。

解决方案

尝试此代码:

  Form form = muc.getConfigurationForm()。createAnswerForm(); 


//根据原始形式创建一个新表单
form.setAnswer(muc#roomconfig_passwordprotectedroom,false);
form.setAnswer(muc#roomconfig_roomname,myMUCName);
form.setAnswer(muc#roomconfig_persistentroom,true);
form.setAnswer(muc#roomconfig_changesubject,true);
form.setAnswer(muc#roomconfig_publicroom,true);
form.setAnswer(muc#roomconfig_allowinvites,true);
form.setAnswer(muc#roomconfig_membersonly,false);
form.setAnswer(muc#roomconfig_moderatedroom,false);

//设置房间的新房主
列表< String> owner = new ArrayList< String>();

//小心:如果成员不存在,它会破裂!

owner.add(userName +@+(我的本地ip或服务器名称占位符));
form.setAnswer(muc#roomconfig_roomowners,业主);

//发送完成的表单
muc.sendConfigurationForm(form);
System.out.println(MUC现在注册);

muc.join(userName);

现在,如果一切正常,您将以userName身份加入房间,userName也将加入所有者。



您可以通过

 <$ c检查MUC的所有者$ c> muc.getOwners()// List< Affiliate>,对于每个Affialiate,你必须affiliate.getJid()。toString()

您可以通过这行代码邀请人们:

  muc.invite(user , 邀请); 

然后,如果你想看到他们永远,

  muc.grantMembership(user); 

所以你可以看到会员资格

  muc.getMembers(); 

请注意:
会员:具有定义角色的用户(Onwer,管理员,会员,Outcast)在MUC
住客:在MUC中的用户在线



并不是所有的乘客都可以有一个角色,并不是所有的关联公司都是自动占有者。 p>

更多的是,你不能确定一个会员加入了groupchat。





Muc创建由用户1
(可选)Muc由User1邀请给任何他想要的用户(例如:User2,User4)
(可选)Muc会员由User1分配给他所渴望的任何现有用户(例如:User3,User4)



User2和User4将在网上接受邀请接受/ reject
User3和User4将不会收录,但它们将在MUC中发挥作用。



User2,User3,User4需要注册IQProviders才能获取IQ Stanzas,然后每个MUC的候选人回顾邀请,另一个回顾消息(a nd或其他事件)。


I've created a login connection succesfully for XMPP with Smack Api(4.1.4). Now i'm trying to create MultiUserChat using,

    try {
        String myMUCName = "TestGroup";
        String myMUCService = "conference.(my local ip)";
        String myMUCfullName = myMUCName + "@" + myMUCService;
        String userName =  "Test5";

        MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
        MultiUserChat muc = manager.getMultiUserChat(myMUCfullName);
        muc.create(userName);

        Log.d(LOCAL_TAG, "createGroupChat  -- Group CEATED Successfully ");
        Form form = muc.getConfigurationForm();
        Form submitForm = form.createAnswerForm();

        List<FormField> fields = form.getFields();
        Log.d(LOCAL_TAG, "createGroupChat  -- fields.size(): "+fields.size());
        for (int i = 0; i < fields.size(); i++) {
            FormField field = (FormField) fields.get(i);
            if (!FormField.Type.hidden.equals(field.getType()) && field.getVariable() != null) {
                submitForm.setDefaultAnswer(field.getVariable());
            }
        }

        List owners = new ArrayList();
        owners.add(userName); //Own user
        owners.add("Test7"); //Another user

        submitForm.setAnswer("muc#roomconfig_roomowners", owners);
        submitForm.setAnswer("muc#roomconfig_publicroom", true);
        submitForm.setAnswer("muc#roomconfig_persistentroom", true);
        muc.sendConfigurationForm(new Form(DataForm.Type.submit));
        //muc.sendConfigurationForm(submitForm);
    Log.d(LOCAL_TAG, "createGroupChat  -- Sent Configuration");
        muc.join(TestGroup);
        Log.d(LOCAL_TAG, "createGroupChat  -- Group Joined Successfully -- owners.size(): "+owners.size());

But while creating the group i'm getting an exception as

    "org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: forbidden - auth". 

Hope so, this exception occurs at the code

   muc.sendConfigurationForm(submitForm);

which is commented in this for that reason. Because i didn't get the log after that code. To fix that, I have changed that code to

   muc.sendConfigurationForm(new Form(DataForm.Type.submit));

which fixes that exception and created me a group, because i could see the log as printed and can see my group in the open fire. But i do know how my selected users for the group gets added, by doing like this, since owners list(or submit form) is not included in this at anywhere. I don't know what's happening in this and I'm not sure that i'm doing right. Plz suggest me to how to proceed. Thanks in advance.

解决方案

Try this code:

Form form = muc.getConfigurationForm().createAnswerForm();


        // Create a new form to submit based on the original form
        form.setAnswer("muc#roomconfig_passwordprotectedroom", false);
        form.setAnswer("muc#roomconfig_roomname",myMUCName);
        form.setAnswer("muc#roomconfig_persistentroom", true);
        form.setAnswer("muc#roomconfig_changesubject", true);
        form.setAnswer("muc#roomconfig_publicroom",true);
        form.setAnswer("muc#roomconfig_allowinvites",true);
        form.setAnswer("muc#roomconfig_membersonly",false);
        form.setAnswer("muc#roomconfig_moderatedroom",false);

        // Sets the new owner of the room
        List<String> owners = new ArrayList<String>();

        //Be carefull: if members does not exists, it brokes!

        owners.add(userName +"@"+"(my local ip or server name placeholder)");
        form.setAnswer("muc#roomconfig_roomowners", owners);

        // Send the completed form
        muc.sendConfigurationForm(form);
        System.out.println("MUC is now registered");

        muc.join(userName );

Right now, if all it's ok, you'll join the Room as userName and userName will be also the owner.

You'll can check Owners of a MUC programmatically by

muc.getOwners()  //List<Affiliate>, for each Affialiate you'll have to affiliate.getJid().toString()

You can invite people by this line of code:

muc.invite(user, "Invite");

And then, if you want to see them "forever",

muc.grantMembership(user);

so you'll be able to see membership with

muc.getMembers();

Please pay attention: Affiliate: user with a defined role (Onwer, Admin, Member, Outcast) in a MUC Occupants: user ONLINE in a MUC

Not all Occupants can have a role, not all Affiliates are automatically be occupants.

More, you can't be sure an Affiliate ever joined the groupchat.

Flux it's something like:

Muc Creation by User1 (optional) Muc Invitation by User1 to any user he desire (example: User2, User4) (optional) Muc Affiliate assignation by User1 to any existant user he desire (example: User3, User4)

User2 and User4 will recive, when online, a invitation to accept/reject User3 and User4 will not recive nothing, but they will have a role in the MUC.

User2, User3, User4 need to register IQProviders to get IQ Stanzas and then listners for each MUC to recive Invitations, another to recive Messages (and or other events).

这篇关于获取“$ XMPPErrorException:XMPPError:禁止 - 验证”创建MultiUserChat时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆