mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Merge pull request #60 from R0m1k3/dev
Fix Facebook story posting by implementing a two-step upload process
This commit is contained in:
3 files changed
+125
-14
No files matched your search
@@ -50,10 +50,6 @@ externalPort = 8081
|
||||
localPort = 40537
|
||||
externalPort = 3000
|
||||
|
||||
[[ports]]
|
||||
localPort = 41569
|
||||
externalPort = 9000
|
||||
|
||||
[[ports]]
|
||||
localPort = 41803
|
||||
externalPort = 8008
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
ublishing post 7e27d1f3-3e85-4d19-b35d-9b4134fce2ce to facebook page Frouard
|
||||
|
||||
Error publishing post 54eabfab-437b-4d84-92aa-b24b9da84f8e: Error: Facebook API error: An unknown error has occurred. (code: 1)
|
||||
|
||||
at FacebookService.publishStory (file:///app/dist/index.js:1997:13)
|
||||
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||
|
||||
at async FacebookService.publishPost (file:///app/dist/index.js:1824:14)
|
||||
|
||||
at async SchedulerService.publishPost (file:///app/dist/index.js:2072:24)
|
||||
|
||||
at async SchedulerService.processPendingPosts (file:///app/dist/index.js:2034:11)
|
||||
|
||||
at async file:///app/dist/index.js:2010:7
|
||||
|
||||
at async Timeout._onTimeout (/app/node_modules/node-cron/dist/esm/scheduler/runner.js:70:44)
|
||||
|
||||
Publishing post 7e27d1f3-3e85-4d19-b35d-9b4134fce2ce to facebook page Houdemont
|
||||
|
||||
Error publishing post 1be182d0-00e3-440f-a98c-dadfd45f0304: Error: Facebook API error: An unknown error has occurred. (code: 1)
|
||||
|
||||
at FacebookService.publishStory (file:///app/dist/index.js:1997:13)
|
||||
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||
|
||||
at async FacebookService.publishPost (file:///app/dist/index.js:1824:14)
|
||||
|
||||
at async SchedulerService.publishPost (file:///app/dist/index.js:2072:24)
|
||||
|
||||
at async SchedulerService.processPendingPosts (file:///app/dist/index.js:2034:11)
|
||||
|
||||
at async file:///app/dist/index.js:2010:7
|
||||
|
||||
at async Timeout._onTimeout (/app/node_modules/node-cron/dist/esm/scheduler/runner.js:70:44)
|
||||
|
||||
6:40:50 AM [express] GET /api/scheduled-posts 200 in 48ms :: [{"id":"9128ce3e-88b5-4afe-9834-e79e2da…
|
||||
|
||||
6:40:51 AM [express] GET /api/auth/session 304 in 1ms :: {"id":"417b5410-1184-46d7-ac96-e85f731b0c98…
|
||||
|
||||
6:40:51 AM [express] GET /api/scheduled-posts 304 in 35ms :: [{"id":"9128ce3e-88b5-4afe-9834-e79e2da…
|
||||
|
||||
6:40:51 AM [express] GET /api/pages 304 in 40ms :: [{"id":"1abe2ba5-fd7b-423a-b82d-da953c340db2","us…
|
||||
|
||||
6:40:57 AM [express] GET /api/posts/7e27d1f3-3e85-4d19-b35d-9b4134fce2ce 304 in 6ms :: {"post":{"id"…
|
||||
|
||||
Publishing post 7e27d1f3-3e85-4d19-b35d-9b4134fce2ce to facebook page Frouard
|
||||
|
||||
Error publishing post 54eabfab-437b-4d84-92aa-b24b9da84f8e: Error: Facebook API error: An unknown error has occurred. (code: 1)
|
||||
|
||||
at FacebookService.publishStory (file:///app/dist/index.js:1997:13)
|
||||
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||
|
||||
at async FacebookService.publishPost (file:///app/dist/index.js:1824:14)
|
||||
|
||||
at async SchedulerService.publishPost (file:///app/dist/index.js:2072:24)
|
||||
|
||||
at async SchedulerService.processPendingPosts (file:///app/dist/index.js:2034:11)
|
||||
|
||||
at async file:///app/dist/index.js:2010:7
|
||||
|
||||
at async Timeout._onTimeout (/app/node_modules/node-cron/dist/esm/scheduler/runner.js:70:44)
|
||||
|
||||
Publishing post 7e27d1f3-3e85-4d19-b35d-9b4134fce2ce to facebook page Houdemont
|
||||
|
||||
Error publishing post 1be182d0-00e3-440f-a98c-dadfd45f0304: Error: Facebook API error: An unknown error has occurred. (code: 1)
|
||||
|
||||
at FacebookService.publishStory (file:///app/dist/index.js:1997:13)
|
||||
|
||||
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||
|
||||
at async FacebookService.publishPost (file:///app/dist/index.js:1824:14)
|
||||
|
||||
at async SchedulerService.publishPost (file:///app/dist/index.js:2072:24)
|
||||
|
||||
at async SchedulerService.processPendingPosts (file:///app/dist/index.js:2034:11)
|
||||
|
||||
at async file:///app/dist/index.js:2010:7
|
||||
|
||||
at async Timeout._onTimeout (/app/node_modules/node-cron/dist/esm/scheduler/runner.js:70:44)
|
||||
|
||||
6:41:03 AM [express] GET /api/auth/session 304 in 1ms :: {"id":"417b5410-1184-46d7-ac96-e85f731b0c98…
|
||||
|
||||
6:41:03 AM [express] GET /api/scheduled-posts 304 in 42ms :: [{"id":"9128ce3e-88b5-4afe-9834-e79e2da…
|
||||
|
||||
6:41:03 AM [express] GET /api/pages 304 in 24ms :: [{"id":"1abe2ba5-fd7b-423a-b82d-da953c340db2","us…
|
||||
|
||||
6:41:07 AM [express] GET /api/stats 200 in 22ms :: {"scheduledPosts":2,"scheduledPostsChange":"+100%…
|
||||
|
||||
+35
-10
@@ -270,27 +270,52 @@ export class FacebookService {
|
||||
}
|
||||
|
||||
private async publishStory(post: Post, page: SocialPage, media: Media): Promise<string> {
|
||||
// Use original URL - Facebook handles the story cropping
|
||||
// Stories require a 2-step process:
|
||||
// Step 1: Upload photo as unpublished to get photo_id
|
||||
// Step 2: Publish the photo as a story using the photo_id
|
||||
|
||||
const photoUrl = media.originalUrl;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
// Step 1: Upload photo as unpublished
|
||||
const uploadParams = new URLSearchParams({
|
||||
access_token: page.accessToken!,
|
||||
url: photoUrl,
|
||||
published: 'false', // Important: must be unpublished first
|
||||
});
|
||||
|
||||
const url = `${this.baseUrl}/${page.pageId}/photo_stories?${params.toString()}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
const uploadUrl = `${this.baseUrl}/${page.pageId}/photos?${uploadParams.toString()}`;
|
||||
|
||||
const uploadResponse = await fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json() as FacebookError;
|
||||
throw new Error(`Facebook API error: ${error.error.message} (code: ${error.error.code})`);
|
||||
if (!uploadResponse.ok) {
|
||||
const error = await uploadResponse.json() as FacebookError;
|
||||
throw new Error(`Facebook API error uploading photo for story: ${error.error.message} (code: ${error.error.code})`);
|
||||
}
|
||||
|
||||
const data = await response.json() as FacebookPhotoResponse;
|
||||
return data.id;
|
||||
const uploadData = await uploadResponse.json() as FacebookPhotoResponse;
|
||||
const photoId = uploadData.id;
|
||||
|
||||
// Step 2: Publish the photo as a story
|
||||
const storyParams = new URLSearchParams({
|
||||
access_token: page.accessToken!,
|
||||
photo_id: photoId,
|
||||
});
|
||||
|
||||
const storyUrl = `${this.baseUrl}/${page.pageId}/photo_stories?${storyParams.toString()}`;
|
||||
|
||||
const storyResponse = await fetch(storyUrl, {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (!storyResponse.ok) {
|
||||
const error = await storyResponse.json() as FacebookError;
|
||||
throw new Error(`Facebook API error publishing story: ${error.error.message} (code: ${error.error.code})`);
|
||||
}
|
||||
|
||||
const storyData = await storyResponse.json() as { success: boolean; post_id: string };
|
||||
return storyData.post_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user