1

I need my bot (me) to login without myself involved in it. I've set up my node server, but now I can't figure out how to login. I'll need fkey to connect to socket, and for that I feel I'll need to login.

secondly, I don't know if I need to login only to stackexchange.com or I'll need to login each site individually if a chat room belongs to different SE.

For example, I've logged in with meta SE, and I'm chatting in The Friendly Cafe room, but then I want to connect to any other room which belongs to different SE site, will I need a different fkey and authentication to connect to socket?

Is this api and login process shared somewhere?

8
  • There is no API, but you could look at one of the libraries mentioned here: stackapps.com/q/4446/34061 Commented Jun 11, 2021 at 13:59
  • @Glorfindel I understand there's no official api, but I have access to chat and events and ws-auth apis. So I need something like that for login too. That will help. Isn't it possible? Commented Jun 11, 2021 at 14:03
  • Yes, but either by reverse engineering or by copying from others who've done that. There's no step by step guide. Commented Jun 11, 2021 at 14:05
  • @Glorfindel oh, so I can copy from libraries and see how it works? Commented Jun 11, 2021 at 14:11
  • 1
    Depends on the license, but probably yes. At least it'll tell you the right URLs and parameters. Commented Jun 11, 2021 at 14:16
  • @Glorfindel I checked the cabbage JS api but looks like it's very old. I'm getting page not found error in API response. Commented Jun 11, 2021 at 18:30
  • In fact looks like all of them are outdated Commented Jun 11, 2021 at 18:32
  • The Python ChatExchange library is in use by several bots, including Smoke Detector. The login logic is not exactly easily penetrable, but you might at least try to validate your findings once you understand what you are doing by comparing to the logic in there. github.com/Manishearth/ChatExchange/blob/master/chatexchange/… Commented Jun 12, 2021 at 9:39

1 Answer 1

3

You can not. Because there is no API. You need to reverse engineer the calls a webbrowser would make when a normal user performs a log in. Once you've collected those calls you need to implement them in your favorite tool stack.

Here is what you need for reverse engineering:

Here is how you proceed (I assume you have a Stack Exchange (Username/password) Account)

  1. Open Firefox and the Developer Console.
  2. In the Network tab make sure Persist Logs is marked
  3. In the Network tab filter on HTML (and optional XHR)
  4. Execute below steps and verify each step in the network console.

(I use this kind of CSS rules notation to indicate what you need from the HTML: a[textContent='log in'].href means: find the <a> that has textContent of log in and then return the value of its href attribute. Do note that the use of textContent is not allowed in proper CSS. I abused it here to keep the notation concise)

action url + data Method Cookies Html / HTTP headers
visit https://chat.stackexchange.com/ GET - next = a[textContent='log in'].href
Click next GET - next = Location header
redirect next GET Prov next = form#login-form.action
fkey_val = input[name='fkey'].value
ssrc_val = input[name='ssrc'].value
cdl_val = input[name='cdl'].value
submit next
fkey=fkey_val&
ssrc=ssrc_val&
cdl=cdl_val&
email=your_email&
password=your_password
POST acct
fkey
uauth
next = a[textContent='Click here if you are not redirected'].href
click next GET - next = Location header
redirect next GET sechatusr (chat main page, logged in)

Implement above steps in your toolstack of choice. Components / classes / functions you minimal need:

And debugging skills.

Be aware of the Etiquette of Screen-scraping Stack Overflow? and pay attention to the User Agent header

8 Comments

Oops. It's indeed very difficult. I'll manually do login in this case whenever I want the bot to run, and use other apis using userscript for sending messages/sockets etc., as they are easy. Anyway, does chatbot do screen-scraping? How do I know if I'm screen-scraping? I mean I'm not storing any information from SE to my pc. I'm just reading the events and sending text messages. That's it. That doesn't mean screen-scraping right?
You are scraping if you parse html and post with a script / code. So yes, any bot active on the SE chatservers does screen scraping. By definition if there is no formal API for interacting with a website, screen-scraping is all that is left if you automate interactions with such websites.
oh. In that case I've lots of doubts how I can avoid being blocked/suspended. Should I leave comments on the question/answer you've mentioned? Or ask a new specific question?
Yeah, please do. I'll have an answer for that as well. In your new question please refer to questions/answers you've read / studied and what your understanding is and what you doubts about.
@Rosie i've added examples of user agents to the FAQ post: stackapps.com/a/8965/18722
|

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.