【问题标题】:Adding photos from instagram to media library wordpress将照片从 instagram 添加到媒体库 wordpress
【发布时间】:2016-10-18 08:06:26
【问题描述】:

我创建了以下 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 );
  }
?>

【问题讨论】:

    标签: php wordpress instagram-api


    【解决方案1】:

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

    应该为您完成这项工作! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2019-11-19
      • 1970-01-01
      • 2020-03-19
      • 2019-12-22
      • 1970-01-01
      相关资源
      最近更新 更多