Merge pull request #758 from gitroomhq/feat/threads-refresh-token
Threads refresh token
This commit is contained in:
commit
598f3a9d37
|
|
@ -25,13 +25,27 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
];
|
||||
|
||||
async refreshToken(refresh_token: string): Promise<AuthTokenDetails> {
|
||||
const { access_token } = await (
|
||||
await this.fetch(
|
||||
`https://graph.threads.net/refresh_access_token?grant_type=th_refresh_token&access_token=${refresh_token}`
|
||||
)
|
||||
).json();
|
||||
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
picture: {
|
||||
data: { url },
|
||||
},
|
||||
} = await this.fetchPageInformation(access_token);
|
||||
|
||||
return {
|
||||
refreshToken: '',
|
||||
expiresIn: 0,
|
||||
accessToken: '',
|
||||
id: '',
|
||||
name: '',
|
||||
picture: '',
|
||||
id,
|
||||
name,
|
||||
accessToken: access_token,
|
||||
refreshToken: access_token,
|
||||
expiresIn: dayjs().add(59, 'days').unix() - dayjs().unix(),
|
||||
picture: url,
|
||||
username: '',
|
||||
};
|
||||
}
|
||||
|
|
@ -153,7 +167,8 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
isCarouselItem = false,
|
||||
replyToId?: string
|
||||
): Promise<string> {
|
||||
const mediaType = media.url.indexOf('.mp4') > -1 ? 'video_url' : 'image_url';
|
||||
const mediaType =
|
||||
media.url.indexOf('.mp4') > -1 ? 'video_url' : 'image_url';
|
||||
const mediaParams = new URLSearchParams({
|
||||
...(mediaType === 'video_url' ? { video_url: media.url } : {}),
|
||||
...(mediaType === 'image_url' ? { image_url: media.url } : {}),
|
||||
|
|
@ -234,19 +249,16 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
form.append('media_type', 'TEXT');
|
||||
form.append('text', message);
|
||||
form.append('access_token', accessToken);
|
||||
|
||||
|
||||
if (replyToId) {
|
||||
form.append('reply_to_id', replyToId);
|
||||
}
|
||||
|
||||
const { id: contentId } = await (
|
||||
await this.fetch(
|
||||
`https://graph.threads.net/v1.0/${userId}/threads`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: form,
|
||||
}
|
||||
)
|
||||
await this.fetch(`https://graph.threads.net/v1.0/${userId}/threads`, {
|
||||
method: 'POST',
|
||||
body: form,
|
||||
})
|
||||
).json();
|
||||
|
||||
return contentId;
|
||||
|
|
@ -324,32 +336,34 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
}
|
||||
|
||||
const [firstPost, ...replies] = postDetails;
|
||||
|
||||
|
||||
// Create the initial thread
|
||||
const initialContentId = await this.createThreadContent(
|
||||
userId,
|
||||
accessToken,
|
||||
userId,
|
||||
accessToken,
|
||||
firstPost
|
||||
);
|
||||
|
||||
|
||||
// Publish the thread
|
||||
const { threadId, permalink } = await this.publishThread(
|
||||
userId,
|
||||
accessToken,
|
||||
userId,
|
||||
accessToken,
|
||||
initialContentId
|
||||
);
|
||||
|
||||
|
||||
// Track the responses
|
||||
const responses: PostResponse[] = [{
|
||||
id: firstPost.id,
|
||||
postId: threadId,
|
||||
status: 'success',
|
||||
releaseURL: permalink,
|
||||
}];
|
||||
|
||||
const responses: PostResponse[] = [
|
||||
{
|
||||
id: firstPost.id,
|
||||
postId: threadId,
|
||||
status: 'success',
|
||||
releaseURL: permalink,
|
||||
},
|
||||
];
|
||||
|
||||
// Handle replies if any
|
||||
let lastReplyId = threadId;
|
||||
|
||||
|
||||
for (const reply of replies) {
|
||||
// Create reply content
|
||||
const replyContentId = await this.createThreadContent(
|
||||
|
|
@ -358,17 +372,17 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
reply,
|
||||
lastReplyId
|
||||
);
|
||||
|
||||
|
||||
// Publish the reply
|
||||
const { threadId: replyThreadId } = await this.publishThread(
|
||||
userId,
|
||||
accessToken,
|
||||
replyContentId
|
||||
);
|
||||
|
||||
|
||||
// Update the last reply ID for chaining
|
||||
lastReplyId = replyThreadId;
|
||||
|
||||
|
||||
// Add to responses
|
||||
responses.push({
|
||||
id: reply.id,
|
||||
|
|
@ -377,7 +391,7 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
|
|||
releaseURL: permalink, // Main thread URL
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return responses;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export class XProvider extends SocialAbstract implements SocialProvider {
|
|||
identifier = 'x';
|
||||
name = 'X';
|
||||
isBetweenSteps = false;
|
||||
scopes = [];
|
||||
scopes = [] as string[];
|
||||
toolTip =
|
||||
'You will be logged in into your current account, if you would like a different account, change it first on X';
|
||||
|
||||
|
|
@ -313,4 +313,24 @@ export class XProvider extends SocialAbstract implements SocialProvider {
|
|||
status: 'posted',
|
||||
}));
|
||||
}
|
||||
|
||||
communities(accessToken: string, data: {search: string}) {
|
||||
const [accessTokenSplit, accessSecretSplit] = accessToken.split(':');
|
||||
const client = new TwitterApi({
|
||||
appKey: process.env.X_API_KEY!,
|
||||
appSecret: process.env.X_API_SECRET!,
|
||||
accessToken: accessTokenSplit,
|
||||
accessSecret: accessSecretSplit,
|
||||
});
|
||||
|
||||
return client.v2.searchCommunities(data.search);
|
||||
|
||||
// })).data.map(p => {
|
||||
// return {
|
||||
// id: p.id,
|
||||
// name: p.name,
|
||||
// accessToken
|
||||
// }
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
package.json
10
package.json
|
|
@ -89,6 +89,7 @@
|
|||
"@solana/wallet-adapter-react-ui": "^0.9.35",
|
||||
"@swc/helpers": "0.5.13",
|
||||
"@sweetalert2/theme-dark": "^5.0.16",
|
||||
"@tailwindcss/postcss": "^4.1.7",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/concat-stream": "^2.0.3",
|
||||
"@types/facebook-nodejs-business-sdk": "^20.0.2",
|
||||
|
|
@ -184,10 +185,10 @@
|
|||
"simple-statistics": "^7.8.3",
|
||||
"stripe": "^15.5.0",
|
||||
"striptags": "^3.2.0",
|
||||
"sweetalert2": "^11.4.8",
|
||||
"sweetalert2": "11.4.8",
|
||||
"swr": "^2.2.5",
|
||||
"tailwind-scrollbar": "^3.1.0",
|
||||
"tailwindcss": "3.4.3",
|
||||
"tailwindcss": "4.1.7",
|
||||
"tldts": "^6.1.47",
|
||||
"tslib": "^2.3.0",
|
||||
"tweetnacl": "^1.0.3",
|
||||
|
|
@ -252,13 +253,12 @@
|
|||
"prisma": "^6.5.0",
|
||||
"react-refresh": "^0.10.0",
|
||||
"sass": "1.62.1",
|
||||
"tailwindcss": "^4.1.5",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.5.4",
|
||||
"vite": "^5.0.0",
|
||||
"vite": "^6.3.5",
|
||||
"vite-tsconfig-paths": "^5.1.4",
|
||||
"vitest": "1.6.0"
|
||||
"vitest": "3.1.4"
|
||||
},
|
||||
"volta": {
|
||||
"node": "20.17.0"
|
||||
|
|
|
|||
960
pnpm-lock.yaml
960
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue