-
Notifications
You must be signed in to change notification settings - Fork 135
Download thread replies with pagination | Proxy for authorization | Disable minification #208
Description
1. New function for loading replies to a thread with pagination support:
Please, instead of:
const post = await threadsAPI.getThreads(postID);
Add a new function:
getThreadsLoggedIn: PaginationPostIDQuerier<GetUserProfileThreadsPaginatedResponse> = async (
postID,
maxID = '',
options = {},
): Promise<GetUserProfileThreadsPaginatedResponse> => {
if (!this.token) {
await this.getToken();
}
if (!this.token) {
throw new Error('Token not found');
}
let data: GetUserProfileThreadsPaginatedResponse | ErrorResponse | undefined = undefined;
try {
const res = await axios.get<GetUserProfileThreadsPaginatedResponse | ErrorResponse>(
`${BASE_API_URL}/api/v1/text_feed/${postID}/replies/${maxID && `?paging_token=${maxID}`}`,
{ ...options, httpsAgent: this.httpsAgent, headers: { ...this._getInstaHeaders(), ...options?.headers } },
);
data = res.data;
} catch (error: any) {
data = error.response?.data;
}
if (data?.status !== 'ok') {
if (this.verbose) {
console.log('[USER Threads] Failed to fetch', data);
}
throw new Error('Failed to fetch user Threads: ' + JSON.stringify(data));
}
return data;
};
interface PaginationPostIDQuerier<T extends any> {
(postID: string, maxID?: string, options?: AxiosRequestConfig): Promise<T>;
}
------------------------------------
2. Remove minification during installation
..Please make sure that when installing with npm install threads-api , unminified data is loaded. I can add a new feature to TS , but I can't submit to github .
------------------------------------
3. Add proxy support to login() and syncLoginExperiments():
....Yesterday I spent several hours to add proxy support for the authorization function in the minified .js - it was crazy .. but I did it. And now, every time I update the library, I will need to change the JS file again.
So if you can, add "httpsAgent: this.httpsAgent" to the login() method in:
const requestConfig: AxiosRequestConfig = {
method: 'POST',
httpsAgent: this.httpsAgent,
headers: this._getAppHeaders(),
..........
And also in the syncLoginExperiments method, "httpsAgent: this.httpsAgent" in:
const res = await axios.post(`${BASE_API_URL}/api/v1/qe/sync/`, this.sign(data), {
headers: {
...this._getAppHeaders(),
Authorization: undefined
'Sec-Fetch-Site': 'same-origin',
...........
httpsAgent: this.httpsAgent,
------------------------------------
P.S. I write code in PHP , Python , so TS is not very comfortable for me. For some reason, I can’t install from source (package errors, despite the fact that they are already installed)
Thanks!