junhoyeo / threads-api

Unofficial, Reverse-Engineered Node.js/TypeScript client for Meta's Threads. Web UI Included.
https://threads.junho.io
MIT License
1.58k stars 134 forks source link

undefined userData with getUserProfile and undefined userID with getToken #188

Closed Aerglonus closed 11 months ago

Aerglonus commented 11 months ago

These are two probably related issues.

When running getToken the reponse contains userID as undefined

const renew = await threadsAPI.getToken()
// Response
//  token : the Bearer token
//  userID: undefined

And when using getUserProfile the reponse is userData undefined but investigating the actual response data res.data is returns a web page instead. res.data.data.userData.user and res.data.data.userData returns undefined.


undefined
TypeError: Cannot read properties of undefined (reading 'userData')

Expected response :

Aerglonus commented 11 months ago

I got it to work by changing the User-Agent seems to respond with data again instead of the webpage.

from: 'User-Agent': Barcelona ${LATEST_ANDROID_APP_VERSION} Android

to : 'User-Agent': Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.199 Safari/537.36

but its breaking things like authentication, likes, etc. so this probably requires adding a new function like _getDefaultDesktopHeaders and _requestDesktopQuery that are used only on the methods that make requests the https://www.threads.net/api/graphql since it appears that this endpoint is used in browsers or am I wrong?

junhoyeo commented 11 months ago

Released v1.5.3