php
  • instagram
  • 2015-09-25 127 views 0 likes 
    0

    我要拉我的頭髮。任何人都可以請幫我把這個工作,我相信這是愚蠢的..我已經得到所有的PHP錯誤消失,但我不能讓圖像顯示。下面的代碼...在Instagram中拉Instagram照片

    <!DOCTYPE html> 
    <html> 
        <link rel="stylesheet" href="jquery.fancybox-1.3.4.css" type="text/css"> 
        <script type='text/javascript' src='jquery.min.js'></script> 
        <script type='text/javascript' src='jquery.fancybox-1.3.4.pack.js'></script> 
        <script type="text/javascript"> 
         $(function() { 
          $("a.group").fancybox({ 
           'nextEffect' : 'fade', 
           'prevEffect' : 'fade', 
           'overlayOpacity' : 0.8, 
           'overlayColor' : '#000000', 
           'arrows' : false, 
          });   
         }); 
        </script> 
    
        <?php 
         // Supply a user id and an access token 
         $userid = "1d458ab0c149424c812e664c32b48149"; 
         $accessToken = "c195717e379f48c68df451cc3d60524a"; 
    
         // Gets our data 
         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; 
         } 
    
         // Pulls and parses data. 
         $result = fetchData("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}"); 
         $result = json_decode($result); 
        ?> 
    
    
        <?php if(!empty($result->data)): ?> 
        <?php foreach ($result->data as $post){ ?> 
        <!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) --> 
        <a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a> 
        <?php } ?> 
        <?php endif ?> 
    </html> 
    

    回答

    0

    你需要的是在不同的點添加一些檢查,以找出什麼是從Instagram回來和處理任何問題。在調試的同時,在各地粘貼var_dump()可以幫助您查看問題所在。

    下面是一些額外的檢查你的PHP部分的示例:

    <?php 
        // Supply a user id and an access token 
        $userid = "USER ID"; 
        $accessToken = "ACCESS TOKEN"; 
    
        // Gets our data 
        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); 
    
         $info = curl_getinfo($ch); 
    
         // Check a response was returned 
         if ($info['http_code'] == '404') { 
          echo ('Error: HTTP 404 returned, bad request'); 
          die(); 
         } 
         curl_close($ch); 
    
         return $result; 
        } 
    
        // Pulls and parses data. 
        $result = fetchData("https://api.instagram.com/v1/users/{$userid}/?access_token={$accessToken}"); 
        $result = json_decode($result); 
    
        // Check the json_decode succeeded 
        if (empty($result)) { 
         echo "Error: JSON not returned from API"; 
         die(); 
        } 
    
        // Check no error was returned from Instagram 
        if ($result->meta->code != 200) { 
         echo "Error: ".$result->meta->error_message; 
         die(); 
        } 
    ?> 
    

    如果你打算做了很多與Instagram的API的工作,你可能想看看在圖書館做大部分的沉重的舉重。目前看來最受歡迎的是This one

    相關問題