1

Im trying to get vine image using cURL but its returning empty.

I want to extract the image from vine meta tags

<meta property="twitter:image:src" content="https://v.cdn.vine.co/r/thumbs/C40D8A18E21388329752896937984_58406422053.35.0.D4119957-7F82-4C6F-94EC-4732C58E79E1.mp4.jpg?versionId=lWIZyat1QyiI8rjnz3KFsbWtuOoUmGFn">`

This is my code

$ch1eckUrl = "https://vine.co/v/51wPzgnEHLb";

function getVineVideoFromImage($ch1eckUrl) {
    $ch1 = curl_init($ch1eckUrl);
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
    $res1 = curl_exec($ch1);
    preg_match('/twitter:image:src.*content="(.*)"/', $res1, $opimage);
    $VineImage = $opimage[1];
}

Applicate if someone can point me what im doing wrong here

Jordyn
  • 1,133
  • 2
  • 13
  • 28
  • done any basic debugging, like `var_dump($res1)` to see if you actually fetched anything? Checked if preg_match actually found something? you're just ASSUMING nothing will ever go wrong, and something will always be found. obviously those are bad assumptions. – Marc B Oct 04 '16 at 19:20
  • `$CheckUrl = "https://vine.co/v/51wPzgnEHLb"` - missing a `;` here, just sayin', if it's your real code. – Funk Forty Niner Oct 04 '16 at 19:22
  • @MarcB When i do the same to get video link it works fine. So means it dose getting the content fine. It just doesn't work for the image – Jordyn Oct 04 '16 at 19:22
  • @Fred-ii- its just for the example. URL is taking from a form. Anyway ill edit and add it. – Jordyn Oct 04 '16 at 19:24
  • 1
    `$ch1eckUrl` - is there supposed to be a `1` in there? Plus, if you meant to use `$checkUrl`, then that variable is case-sensitive for `$CheckUrl`. See what error reporting has to say, either way. http://php.net/manual/en/function.error-reporting.php and depends how you're calling that `getVineVideoFromImage()` function. – Funk Forty Niner Oct 04 '16 at 19:25
  • Possible duplicate of [How to get Vine video url](http://stackoverflow.com/questions/14549745/how-to-get-vine-video-url) – Anuga Oct 04 '16 at 20:42
  • @Anuga If you're going to mark it as a possible duplicate; why the answer? – Funk Forty Niner Oct 04 '16 at 21:11
  • @Jordyn So... where does this question stand? You've been given an answer also. If that answer solves it, then the question does have a possible duplicate. – Funk Forty Niner Oct 04 '16 at 21:11
  • Acctually, I removed the flag when I realized she wanted the image url and not the video. – Anuga Oct 04 '16 at 21:12

1 Answers1

1

The Answer is already posted here:How to get Vine video url

You've even copied an answer. Just replace twitter:player:stream. with twitter:image:src.

My bad, didn't read Image

On that note, there's an even easier way:

<?php

    $ch1eckUrl = 'https://vine.co/oembed/51wPzgnEHLb.json';

    function getVineVideoFromImage($ch1eckUrl) {

        $json = json_decode(file_get_contents($ch1eckUrl), true);

        return $json['thumbnail_url'];

    }

    $VineImage = getVineVideoFromImage($ch1eckUrl);

    echo($VineImage);

?>

Vine servers JSON, so just fetch that and decode it and you got the url.

Community
  • 1
  • 1
Anuga
  • 2,619
  • 1
  • 18
  • 27