Trying to create a Quickblox group chat dialog, ge

2019-09-12 17:03发布

问题:

I'm attempting to create a group chat dialog in quickblox entirely through the REST API. How to create a user, a session, login, and then create a chat dialog all from the REST API? I can only successfully do the first two.

The tutorial has examples: http://quickblox.com/developers/Authentication_and_Authorization#API_User_Sign_In

I am able to create a session and create a user, after that I can't do more. When I try to login a user, as the example above, using this from the tutorial with my token and user:

curl -X POST \
 -H "Content-Type: application/json"\
 -H "QuickBlox-REST-API-Version: 0.1.0" \
 -H "QB-Token: bee57951d76c03ffdecaad65bba039f4ad413ed7" \
 -d '{"login": "Laralara", "password": "12345678"}' \
 http://api.quickblox.com/login.json

I get Error:

 curl: (6) Could not resolve host: QuickBlox-REST-API-Version
 {"errors":{"login":["(or email) cannot be blank"],"password":["cannot be blank"]}}

No matter what I put in the data "-d" I get the same response.

If I try to create a chat dialog directly like in the example using this: http://quickblox.com/developers/Chat#Create_dialog

curl -X POST \
 -H "Content-Type: application/json"\
 -H "QuickBlox-REST-API-Version: 0.1.0" \
 -H "QB-Token: ffed2e8da05b7a858ddee861ff31a09886aef540" \
 -d '{"type": 2, "name": "Chat Bob, Sam, Garry", "id": "17435", "occupants_ids": "5712780"}' \
 http://api.quickblox.com/chat/Dialog.json

I get Error:

curl: (6) Could not resolve host: QuickBlox-REST-API-Version
{"errors":{"base":["Forbidden. Need user."]}}

Thanks.

回答1:

Please make sure that the user with this login and password exists. Please go to admin panel and check whether there is such user and check is username and password match.



回答2:

There are 4 Steps need to maintain in quickblox.

  1. Create App Session (without user) using QBAuth service.
  2. Sign in to application with valid user details.
  3. Login to Chat Services
  4. Create session with logged in user.

Usually people created session and start working on one-to-one chat. If you followed till step 3, you won't get any problem.

Once you started creating public or private group, you will get an error

{"errors":{"base":["Forbidden. Need user."]}}

To resolve this error, you have to complete step 4. That is create AppSession or QBAuth session using a valid user (login and password).

After completing step 4, you can access all QuickBlox services like creating Group, joining room, sending and receiving messages in a group etc.

Try this.

It works for me on Android. :)

Cheers.



回答3:

Your fields login and password are wrong. You should use user[login]and user[password].

Take a look at this example in the Quickblox documentation: https://quickblox.com/developers/Generate_session_in_PHP