2017-07-27 11 views
0

を使用してInstagramのページからポストの内容を取得するには、単純なphpPHP - シンプルなPHP

を使用してInstagramのページthe contents of an postを取得する方法があり、私はいくつかの検索を行なったし、私は

$url = 'https://www.instagram.com/pagename/'; 
$str = file_get_contents($url); 
$count = 0; 
if(preg_match('#followed_by": {"count": (.*?)}#', $str, $match)) { 
    $count = $match[1]; // get the count from Regex pattern 
    } 
echo $count; 
このスクリプトを見つけました

しかし、そこにはフォロワーの数だけが得られています Instagram投稿の内容同じ概念を使用していますか?

+0

です。 「投稿データ」はHTTP POSTデータ、またはInstagram投稿の内容を意味しますか?どのような場合でも、これは物事を行う悪い方法のようです。 Webサービスを介してInstagramと対話するためのライブラリやAPIがあります。それらはGoogleです。 – Andy

+0

私は今APIがありますが、私はwanaになりました。上記の例のようにするオプションがある場合は – M0ns1f

+2

上記の例では、URLのHTMLソース全体を読み込み、マークアップいくつかのコンテンツを試してみる。答えは、そうです、あなたが望むコンテンツの特定のビットを抽出する方法を理解できるかどうかです。しかし、Instagramがページマークアップを変更した場合、アプリケーションが壊れるなど、それを行うのはひどく信頼できない方法です。適切なライブラリを使用し、適切に処理します。 https://github.com/cosenary/Instagram-PHP-API – Andy

答えて

0

しかし、彼はそれが信頼性の高いではないと私は@Andyアドバイスを取り、それがだから、これは私が上に行くために見つけたものです

汚いAFですhtml

Instagramがページマークアップを変更すると、アプリケーションが壊れます。

それはあなたが求めているものは不明だこの

$username = 'username'; 
    $instaResult= 
    file_get_contents('https://www.instagram.com/'.$username.'/media/'); 
    //decode json string into array 

    $data = json_decode($instaResult); 

foreach ($data as $posts) { 
    foreach($posts as $post){ 
    $postit = (array) json_decode(json_encode($post), True); 
    /* get post text and image */ 
       echo '<p>' .$postit["caption"]["text"].'</p>'; 
       echo '<img src="'.$postit["images"]["standard_resolution"]["url"].'" />'; 
       echo "</br>-----------</br>"; 
    } 
    } 
0

ここには(今日の)動作するコードがあります。 @Andyはそれが信頼性がないと、それは汚いAFだ、言ったように:)

<?php 

$source = file_get_contents("https://www.instagram.com/p/POST_ID/"); 

preg_match('/<script type="text\/javascript">window\._sharedData =([^;]+);<\/script>/', $source, $matches); 

if (!isset($matches[1])) 
    return false; 

$r = json_decode($matches[1]); 

print_r($r); 

// Example to get the likes count 
// $r->entry_data->PostPage[0]->graphql->shortcode_media->edge_media_preview_like->count