如何从Instagram中获取图像在PHP中裁剪?

时间:2017-10-04 15:29:49

标签: php curl instagram instagram-api

我使用curl从我的Instagram获取图像,直到2个月前,默认情况下会修剪standard_resolution标签,但现在它们显示为原始大小。如何才能再次拍摄图像?这是我的代码

<?php
    function gallery() {

        $user_id = ;
        $client_id = "";
        $token = "";
        $url = "https://api.instagram.com/v1/users/".$user_id."/media/recent/?access_token=".$token;

        function fetchData($link) {
            $ch = curl_init(); //initalise curl session
            curl_setopt($ch, CURLOPT_URL, $link); //url to process (can be fed directly into init parameter)
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //does not  check the existence of a common name in the SSL peer certificate (optional)
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //stop cURL from verifying the peer's certificate
            curl_setopt($ch, CURLOPT_POST, 0); //do a regular HTTP POST if set to 1
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); //info type
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //set to true stops it returning json as string 
            $output = curl_exec($ch); //executes curl session 
            curl_close($ch); //close curl session
            return $output;
        }

        $result = json_decode(fetchData($url)); //Decodes a JSON string
        $posts = $result->data;

        foreach($posts as $post){ ?>
            <li class="gallery__item">
                <a target="_blank" href="<?=$post->images->standard_resolution->url; ?>">
                    <img class="gallery__img" src="<?=$post->images->standard_resolution->url; ?>">
                </a>
            </li>
    <?php }
    }
?>

0 个答案:

没有答案