Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

How are we obtaining the x-fb-lsd token? #26

Closed
nasty-nick-tv opened this issue Jul 7, 2023 · 6 comments
Closed

How are we obtaining the x-fb-lsd token? #26

nasty-nick-tv opened this issue Jul 7, 2023 · 6 comments
Labels
question Further information is requested

Comments

@nasty-nick-tv
Copy link

Hi,

I am copying these calls into a Java client.

How can we obtain the 'x-fb-lsd' token?

Thanks

@junhoyeo junhoyeo added the question Further information is requested label Jul 7, 2023
@junhoyeo
Copy link
Owner

junhoyeo commented Jul 7, 2023

Hi @nasty-nick-tv! We obtain the token by parsing the HTML doc.

This logic is inside both getUserIDfromUsername and getPostIDfromURL. We use it to update the token each time those methods are called.

const res = await axios.get(postURL, {
httpAgent: new http.Agent({ keepAlive: true }),
});
let text: string = res.data;
text = text.replace(/\s/g, '');
text = text.replace(/\n/g, '');
const postID: string | undefined = text.match(/{"post_id":"(.*?)"}/)?.[1];
const lsdToken: string | undefined = text.match(/"LSD",\[\],{"token":"(\w+)"},\d+\]/)?.[1];

Best of luck with your client! I would greatly appreciate it if you could reference my work here (Rest assured, I'll do the same for you in this project's README.md).

@junhoyeo junhoyeo changed the title x-fb-lsd How do we obtain the 'x-fb-lsd' token? Jul 7, 2023
@junhoyeo junhoyeo changed the title How do we obtain the 'x-fb-lsd' token? How do we obtain the x-fb-lsd token? Jul 7, 2023
@junhoyeo junhoyeo changed the title How do we obtain the x-fb-lsd token? How are we obtaining the x-fb-lsd token? Jul 7, 2023
@Digital39999
Copy link
Contributor

Question, how do we get fbLSDToken for ThreadsAPI options?

@junhoyeo
Copy link
Owner

junhoyeo commented Jul 7, 2023

Question, how do we get fbLSDToken for ThreadsAPI options?

Hi, @Digital39999! Currently, this library threads-api only supports reading data from Threads. fbLSDToken is the value used in GraphQL requests to Threads.

  1. You don't need to set fbLSDToken manually. The package includes an default value you can use without zero setup, and updates internal state automatically when it requests to raw doc. You can just initialize ThreadsAPI with empty options:
const threadsAPI = new ThreadsAPI()
  1. If you still want to set fbLSDToken yourself, you can retrieve it in your own way using the upper code snippet I added to answer @nasty-nick-tv's question, and pass like the following:
const threadsAPI = new ThreadsAPI({
  fbLSDToken,
  noUpdateLSD: true /* default is `false`, if you want to fix `fbLSDToken` with your provided value, set to `true` */
})`

@Digital39999
Copy link
Contributor

Digital39999 commented Jul 7, 2023

Ah thank you for information, are there any rate-limits you occurred yet? It seems that it starts redirecting after too many requests, which isn't ideal, could you add a handler for that?

Also noUpdateLSD is in method options, not in class constructor.

@Digital39999
Copy link
Contributor

Added custom proxy options in #32 to sort of prevent this from happening.

@junhoyeo
Copy link
Owner

junhoyeo commented Jul 7, 2023

Also noUpdateLSD is in method options, not in class constructor.

Oops, my bad. Should've fixed this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants