pedramardakani / API_PHP_Fetch_Trailer

A minimal working example of creating and authenticating a php GET request to an API, and converting the JSON response to a php object.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Table of Contents

  1. Minimal PHP code to retrieve movie trailer links from TMDb API

Minimal PHP code to retrieve movie trailer links from TMDb API

This example code uses the TMDb API but is not endorsed or certified by TMDb.

  1. Subscribe to TMDb with a valid email address

  2. Get the API validation key

  3. Read terms-of-use

  4. Authenticate the api

  5. Use the manual

  6. Add the video ID like this:

    https://www.youtube.com/watch?v={{video_id}}

  7. Check if PHP cURL is available already curl --version if not, just Configure curl on machine

  8. Use the cURL documentation to write a simple script

  9. Get the trailer link via TMDb API

  10. Embed youtube trailer of the movie like this:

    <?php
    // A simple example key:
    $trailer_key = 'G4_ULVw5L04';
    $trailer_url = 'https://www.youtube.com/embed/' . $trailer_key;
    
    // Minimal iframe
    $embed_this = '<iframe src="' . $trailer_url . '"></iframe>';
    ?>
    

About

A minimal working example of creating and authenticating a php GET request to an API, and converting the JSON response to a php object.

License:MIT License


Languages

Language:PHP 100.0%