• <?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://api.instagram.com/v1/users/**/media/recent/?access_token=******.*******&count=60");
    
      $result = json_decode($result);
      foreach ($result->data as $post) {
         if(empty($post->caption->text)) {
           // Do Nothing
         }
         else {
            echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
            <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
            </a>';
         }
    
      }
    ?>

    I got this bit of code to pull instagram images, it works on some online compiler but i cant make it work on wordpress any idea how?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am not too familiar with cURL.. but I think the HTTP API from the Codex is more of what you want to do.

    Thread Starter halluzineyt

    (@halluzineyt)

    <?php
    
    $result = wp_remote_get( "https://api.instagram.com/v1/users/***********/media/recent/?access_token=**********6" );
    
      $result = json_decode($result);
      foreach ($result->data as $post) {
         if(empty($post->caption->text)) {
           // Do Nothing
         }
         else {
            echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
            <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
            </a>';
         }
    
      }
    ?>

    i tried this still doesnt work/

    Thread Starter halluzineyt

    (@halluzineyt)

    <?php
    
      $result = wp_remote_get("https://api.instagram.com/v1/users/*********/media/recent/?access_token=*********&count=60", true);
    	$decode = json_decode($result['body'], true);
    
      foreach ($decode->data as $post) {
         if(empty($post->caption->text)) {
           // Do Nothing
         }
         else {
            echo '<a class="instagram-unit" target="blank" href="'.$post->link.'">
            <img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="50" height="auto" />
            </a>';
         }
    
      }
    ?>

    Can you check this one?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Make curl/json work on wordpress’ is closed to new replies.