Skip to content

[TikTokBridge] Use oEmbed for video metadata#4514

Merged
dvikan merged 4 commits intoRSS-Bridge:masterfrom
ApolloFops:tiktok-metadata
May 9, 2025
Merged

[TikTokBridge] Use oEmbed for video metadata#4514
dvikan merged 4 commits intoRSS-Bridge:masterfrom
ApolloFops:tiktok-metadata

Conversation

@ApolloFops
Copy link
Contributor

Fetches oEmbed-formatted metadata for videos through the TikTok API to provide post titles, thumbnails, and authors. I'm not caching JSON responses so it has the potential to be a bit slow in theory, but in my testing this doesn't appear to cause any noticeable performance issues (I'm not super familiar with PHP so I'm not entirely sure how to add this if it is needed).

Fetches oEmbed-formatted metadata for videos through the TikTok API to
provide post titles, thumbnails, and authors. This hasn't yet been
tested, so it's possible it doesn't work.
@github-actions
Copy link

github-actions bot commented Apr 7, 2025

Pull request artifacts

Bridge Context Status
TikTok 1 By user (current) ✔️
TikTok 1 By user (pr) ✔️

last change: Sunday 2025-05-04 15:54:49

@ApolloFops
Copy link
Contributor Author

I've been running with this patch on my instance for a little while, and it looks like the TikTok oEmbed API actually occasionally returns 400 bad request, even with a valid URL. I'll investigate this a bit more, and try to implement a fix (I figure I can probably just check if the request is successful and, in the case that it is not, just retry a few times, since it seems to work fine after re-sending the request).

Here's the error output if anyone's interested.

HttpException: https://tiktok.com/oembed?url=https://www.tiktok.com/@domtheyeen/video/7481770411840032031 resulted in 400 Bad Request in lib/http.php line 36

index.php(73): RssBridge->main()
lib/RssBridge.php(39): RssBridge->{closure}()
lib/RssBridge.php(37): CacheMiddleware->__invoke()
middlewares/CacheMiddleware.php(44): RssBridge->{closure}()
lib/RssBridge.php(37): ExceptionMiddleware->__invoke()
middlewares/ExceptionMiddleware.php(17): RssBridge->{closure}()
lib/RssBridge.php(37): SecurityMiddleware->__invoke()
middlewares/SecurityMiddleware.php(19): RssBridge->{closure}()
lib/RssBridge.php(37): MaintenanceMiddleware->__invoke()
middlewares/MaintenanceMiddleware.php(10): RssBridge->{closure}()
lib/RssBridge.php(37): BasicAuthMiddleware->__invoke()
middlewares/BasicAuthMiddleware.php(13): RssBridge->{closure}()
lib/RssBridge.php(37): TokenAuthenticationMiddleware->__invoke()
middlewares/TokenAuthenticationMiddleware.php(10): RssBridge->{closure}()
lib/RssBridge.php(34): DisplayAction->__invoke()
actions/DisplayAction.php(54): DisplayAction->createResponse()
actions/DisplayAction.php(89): TikTokBridge->collectData()
bridges/TikTokBridge.php(45): getContents()
lib/contents.php(118): HttpException::fromResponse()
lib/http.php(36)

Query string: action=display&context=By+user&username=%40domtheyeen&bridge=TikTokBridge&format=Atom
Version: 2025-01-26 (git.tiktok-metadata.ffe2d02)
Os: Linux
PHP version: 8.2.28

@ApolloFops ApolloFops marked this pull request as draft April 10, 2025 00:30
@dvikan
Copy link
Contributor

dvikan commented Apr 10, 2025

ok cool

The non-www URL resulted in a 301 redirect to the www URL, so this just
skips that redirect, improving performance a bit and hopefully helping
with the 400 errors.
If an OEmbed request fails, retry a few times, waiting a bit in between
each retry. This should fix the problem for the most part, since I think
the problem was related to some sort of rate limit (it isn't mentioned
in the docs, but it seems to only happen when sending large quantities
of sequential requests).
@ApolloFops
Copy link
Contributor Author

I added some retry logic, and it seems to be working pretty consistently now (I wrote that patch about a week ago, and I don't think it's happened since - my RSS aggregator is fetching 6 TikTok feeds every ~15 minutes, so it was happening about once every 1.5 days before).

@ApolloFops ApolloFops marked this pull request as ready for review May 4, 2025 18:08
@dvikan dvikan merged commit 5bd767b into RSS-Bridge:master May 9, 2025
3 of 9 checks passed
@dvikan
Copy link
Contributor

dvikan commented May 9, 2025

#4550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants