将照片从instagram添加到媒体库wordpress

时间:2016-10-18 08:06:26

标签: php wordpress instagram-api

我创建了以下php文件来获取特定用户的Instagram照片。任何人都可以指出我正确的方向,然后我可以将这些照片添加到我的wordpress网站的媒体库中吗?

<?php
/**
 * Template Name: Cronjob
 */

  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=5");
  $result = json_decode($result);
  foreach ($result->data as $post) {

    $new_post = wp_insert_post( array(
        'post_content'  => '<a href="'. esc_url( $post->link ) .'" target="_blank"><img src="'. esc_url( $post->images->standard_resolution->url ) .'" alt="'. $post->caption->text .'" /></a>',
        'post_name'     => $post->id,
        'post_type' => 'instagram'
    ), true );
  }
?>

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用Instagram Importer-Plugin

应该为你做好准备! :)