Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature facebook thumbnail api #387

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
import { FC } from 'react';
import { withProvider } from '@gitroom/frontend/components/launches/providers/high.order.provider';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
import { MediaComponent } from '@gitroom/frontend/components/media/media.component';

export default withProvider(null, undefined, undefined, undefined, 63206);
const FacebookSettings: FC = () => {
const { register } = useSettings();
return (
<div className="mt-[20px]">
<MediaComponent
type="image"
width={1280}
height={720}
label="Video Thumbnail"
description="Thumbnail for video posts (optional)"
{...register('thumbnail')}
/>
</div>
);
};

export default withProvider(
FacebookSettings,
undefined,
undefined,
undefined,
63206
);
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
};
}

async uploadVideoThumbnail(
accessToken: string,
videoId: string,
thumbnailUrl: string
): Promise<void> {
const response = await this.fetch(
`https://graph.facebook.com/v20.0/${videoId}/thumbnails`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
access_token: accessToken,
is_preferred: true,
source: thumbnailUrl,
}),
}
);

if (!response.ok) {
const errorData = await response.json();
throw new Error(
`Failed to upload video thumbnail: ${JSON.stringify(errorData)}`
);
}
}

async authenticate(params: {
code: string;
codeVerifier: string;
Expand Down Expand Up @@ -202,6 +230,13 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {

finalUrl = 'https://www.facebook.com/reel/' + videoId;
finalId = videoId;
if (firstPost.settings?.thumbnail?.url) {
await this.uploadVideoThumbnail(
accessToken,
videoId,
firstPost.settings.thumbnail.url
);
}
} else {
const uploadPhotos = !firstPost?.media?.length
? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export type PostResponse = {
export type PostDetails<T = any> = {
id: string;
message: string;
settings: T;
settings: T & {
thumbnail?: {
url: string;
};
};
media?: MediaContent[];
poll?: PollDetails;
};
Expand Down