ssovit / TikTok-API-PHP

Unofficial TikTok API for PHP. Join our Discord server
https://discord.gg/rSQd2QAXA8
MIT License
145 stars 42 forks source link

I don't know why the video is not shown #31

Closed georgesabin closed 3 years ago

georgesabin commented 3 years ago

Hi!

I tried to use your example from the stream.

Can you tell me if I'm using correct the stream?

<video width="320" height="240" controls>
            <source src="<?php $streamer->stream($tikTok['playAddr']); ?>" type="video/mp4">
        </video>

https://ibb.co/JqRgKJk

ssovit commented 3 years ago

Stream class won't put our the video streaming url, instead it will stream the video

So,

  1. you need to create stream.php file which will take a url param like videoUrl or something so you in your stream.php file you can do something like

    ///some initializations
    $streamer->stream(base64_decode(urldecode($_GET['videoUrl'])));
  2. then in your video tag you do something like

    <source src="stream.php?videoUrl=<?php echo urlencode(base64_encode(($tikTok['playAddr'])); ?>" type="video/mp4">
georgesabin commented 3 years ago

Thank you for the response.

I did exactly what you said, but now I received a 403 status code, Forbidden.

https://ibb.co/jhvbphR

Do you have any idea why?

P.S.: I'm using wordpress.

Thanks!

ssovit commented 3 years ago

You should create ajax hook using WP hook which will handle the streaming function and use that ajax url in video src attribute.

https://developer.wordpress.org/reference/hooks/wp_ajax_action/

Use something like this in your theme's functions.php or plugin file

add_action('wp_ajax_tt_video_stream','tiktok_video_streamer');// for logged in users
add_action('wp_ajax_nopriv_tt_video_stream','tiktok_video_streamer'); // for non logged in users

function tiktok_video_streamer(){
  // this handles the ajax request when action=tt_video_stream
   $url=base64_decode(url_decode($_GET['url']));
   $streamer->stream($url); // assuming you already have created $streamer instance
   die();
}

In your video tag <source src="<?php echo admin_url('admin-ajax.php')?action=tt_video_stream&url=<?php echo urlencode(base64_encode(($tikTok['playAddr'])); ?>" type="video/mp4">

georgesabin commented 3 years ago

I tried in this way, but without success also.

I still get 403 https://ibb.co/syQkjkx

The stream instance should be with a cookie file from tik tok?

ssovit commented 3 years ago

Make sure the cookie_file are the same when initializing both Streamer & Api classes. This library handles the cookies across so it shouldn't matter.

This issue is unrelated to the library. You should hire WordPress expert for the integration if you don't have experience with WP ajax.

georgesabin commented 3 years ago

Understand, but for getTrendingFeed method works fine and for getChallengeFeed not working.

georgesabin commented 3 years ago

Resolved! Cookie file was the problem.

Ssovit, thanks for the suport!

P.S.: Amazing API, good job!