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