2015-06-11 49 views
2

我想在我的網站上嵌入20張Instagram照片。這些照片是爲每個頁面不同,我收到的所有在PHP數組的Instagram的URL在本格式嵌入多張Instagram照片的最有效方法是什麼?

https://instagram.com/p/xxxxxxxxxx/media/?size=m 

我目前只使用一個foreach循環和嵌入他們這樣

<img src="https://instagram.com/p/xxxxxxxxxx/media/?size=m"> 
<img src="https://instagram.com/p/xxxxxxxxxy/media/?size=m"> 
<img src="https://instagram.com/p/xxxxxxxxxz/media/?size=m"> 

我認爲這不是最有效的方法,因爲每個圖像的src必須重定向到實際的源。

我發現的唯一的另一種方法是這樣的URL

https://api.instagram.com/oembed/?url=https://instagram.com/p/xxxxxxxxxx/media/?size=m 

但使用這種方法將意味着我需要的JSON解碼每個圖像找到它的實際來源。


有沒有一些方法,我可以在https://instagram.com/p/xxxxxxxxxx/media/?size=m URL轉換爲直接圖像URL沒有幾十個服務器調用的?

+1

你關心的是在Instagram服務器上解析這些URL,對吧?我不擔心它,除非你有一些實際的性能問題... Instagram的CDN,緩存等設置服務這些圖像 –

回答

0

獲得直接圖像鏈接的唯一方法是進行API調用。

如果你通過API這些圖片,你只需要檢查響應的圖像節點,例如:

"images": { 
     "low_resolution": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_6.jpg", 
      "width": 306, 
      "height": 306 
     }, 
     "thumbnail": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_5.jpg", 
      "width": 150, 
      "height": 150 
     }, 
     "standard_resolution": { 
      "url": "http://distillery.s3.amazonaws.com/media/2010/07/16/4de37e03aa4b4372843a7eb33fa41cad_7.jpg", 
      "width": 612, 
      "height": 612 
     } 
    }, 

更多細節上的API響應可以在這裏找到:https://instagram.com/developer/endpoints/media/

如果你沒有通過API的圖像,你嵌入他們的方式是最好的方式,你不應該關心性能問題,它會很好:)

0

Instagram的API只提供單一職位或照片嵌入您的網站。 你需要使用第三方工具來嵌入多個Instagram照片。有很多第三方工具,但我強烈建議使用SnapWidget

相關問題