mattkrupnik
mattkrupnik

Reputation: 527

Get Instagram data via CURL

Where is error in below code? I try take the data from instagram website, for example https://www.instagram.com/nasa/media/ - I want to take it in this way don't want use API. At the moment every thing work if I take data via file_get_contents but want take it via curl - is faster

<?php

function fetchData($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$result = fetchData('https://www.instagram.com/nasa/media/');
$result = json_decode($result);

?>

Upvotes: 3

Views: 8905

Answers (1)

Ren&#233; H&#246;hle
Ren&#233; H&#246;hle

Reputation: 27295

I don't think that file_get_contents is so much slower then curl. In the end it depends on the response time of the server you're trying to get the information and how much requests you do.

So i would prefer file_get_contents in your case its much easier and needs less code. And the much important thing... its working ;)

$result = file_get_contents('https://www.instagram.com/nasa/media/');

Upvotes: 1

Related Questions