如何解决未初始化的字符串偏移量?

时间:2017-09-05 16:30:55

标签: php wordpress crash instagram-api

我遇到了一些问题。我已经制作了一个wordpress插件,它会自动获取最近的20个Instagram帖子,然后理论上它应该让我将最新的图像作为短代码插入到帖子中。基本上,我收到一条显示错误消息:

Notice: Uninitialized string offset: 0 in D:\XEMP\htdocs\xd\wordpress\wp-content\plugins\insta-live\insta-live.php on line 29

现在,重现这个的代码是:

//define Access token
$accesst= "PUT YOUR INSTAGRAM ACCESS TOKEN HERE";
//userid
$userid= YOUR INSTAGRAM USER ID HERE;
//image count to get
$count=20;
//get api contents
$content = file_get_contents('https://api.instagram.com/v1/users/self/media/recent/?access_token='.$accesst.'&count='.$count);
//converting JSON to object
$standardres = json_decode($content, true);
//array method
foreach($standardres['data'] as $photo) {
   $imageData = base64_encode(file_get_contents($photo['images']['standard_resolution']['url']));
   $images[] = '<img src="data:image/jpeg;base64,' . $imageData . '" />';
}



//create functions for shortcodes
function fone($images){
    return $images[0]; //naudok tik [one]
} 
//shortcodes
add_shortcode( 'one', 'fone');
?>

任何想法如何解决这个问题? var_dump()为我提供了标题上方的图片..

0 个答案:

没有答案