I am using TMDB (The Movie Database) API. I am stuck in watch video functionality. How can I add watch video functionality with suitable code?
I'm trying to use the TMDB API to insert a film already seen into the TMDB platform from my web app (the reference API is https://developer.themoviedb.org/reference/account-add-to-watchlist)
My code is as follows, but it doesn't work (the answer is invalid parameters):
$response = $client->request('POST', 'https://api.themoviedb.org/3/account/' . $account_id . '/watchlist', [
'headers' => [
'Authorization' => 'Bearer xxxxxkeyxxxx',
'accept' => 'application/json',
'content-type' => 'application/json',
'media_type' => 'movie',
'media_id' => $media_id,
'watchlist' => true
],
]);
Compared to the example API in the TMDB API documentation, I tried adding the parameters to indicate the film already seen, in this way:
'media_type' => 'movie',
media_id' => $media_id,
'watchlist' => true
But I think I'm doing it wrong.
Can anyone give me help?
Those parameters ('media_type','media_id', and 'watchlist') should be inserted in the request data not in the header. Also in the API url, you have to pass some query parameters like api_key and session_id so it would be something like this:
https://api.themoviedb.org/3/account/:account_id/watchlist?api_key=XXXXXXXXXX&session_id=XXXXXXXXXX. In order to generate a session id before you have to create a token(if the current expired) and authorize that request token, here's more info on the documentation: https://developer.themoviedb.org/reference/authentication-how-do-i-generate-a-session-id. I'm not really an expert in php, but here's a snipet code in javascript (i'm using express framework).