내 사이트 중 하나의 메인 페이지에서 가장 최근의 3 개의 그림을 Instagram 피드로 표시합니다. 최근특정 해시 태그로 Instagram 사진 가져 오기
function rudr_instagram_api_curl_connect($api_url){
$connection_c = curl_init(); // initializing
curl_setopt($connection_c, CURLOPT_URL, $api_url); // API URL to connect
curl_setopt($connection_c, CURLOPT_RETURNTRANSFER, 1); // return the result, do not print
curl_setopt($connection_c, CURLOPT_TIMEOUT, 20);
$json_return = curl_exec($connection_c); // connect and get json data
curl_close($connection_c); // close connection
return json_decode($json_return); // decode and return
}
$access_token = 'access_token';
$image_return = 3;
$user_search = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/self/media/recent?access_token=".$access_token);
$user_id = $user_search->data[0]->id; // or use string 'self' to get your own media
$return = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/self/media/recent?access_token=".$access_token."&count=".$image_return);
// var_dump($return); // if you want to display everything the function returns
foreach ($return->data as $post) {
echo '<div class="col-sm-12 col-md-4 mb-3 text-center">
<a href="'.$post->link.'" target="_blank">
<img src="' . $post->images->standard_resolution->url . '" class="img-fluid img-thumbnail bx-shadow"/>
</a>
<p><i class="fa fa-tag" aria-hidden="true"></i> ' . $post->caption->text . '<br><i class="fa fa-heart" aria-hidden="true"></i> '.$post->likes->count.' <i class="fa fa-comment" aria-hidden="true"></i> '.$post->comments->count.'<br><i class="fa fa-clock-o" aria-hidden="true"></i> ' . date('M j, Y', $post->created_time) . '</p>
</div>';
}
내가 난 단지 검색 할 수있는 방법을 찾을 거라고 생각 그래서 내가 반드시 사이트에 표시하지 않도록 인스 타 그램에 사진을 업로드했습니다 : 나는 다음과 같은 코드로이 달성 한 특정 해시 태그가있는 이미지 빠른 Google 검색에서 여러 솔루션이 나타 났지만 하나는 기존 코드와 유사했습니다. 이 솔루션은 여기에서 찾을 수 있습니다 : Fetch All Photos With A Hashtag
나는 내가 $hashtag = "bodypiercing";
의 변수를 추가하고 $return = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/tags/".$hashtag."https://stackoverflow.com/users/self/media/recent?access_token=".$access_token."&count=".$image_return);
로 URL에 추가하여 내 코드를 수정 단순히 URL에 tags
변수가 있었다 용액에 나타났습니다.
function rudr_instagram_api_curl_connect($api_url){
$connection_c = curl_init(); // initializing
curl_setopt($connection_c, CURLOPT_URL, $api_url); // API URL to connect
curl_setopt($connection_c, CURLOPT_RETURNTRANSFER, 1); // return the result, do not print
curl_setopt($connection_c, CURLOPT_TIMEOUT, 20);
$json_return = curl_exec($connection_c); // connect and get json data
curl_close($connection_c); // close connection
return json_decode($json_return); // decode and return
}
$access_token = 'access_token';
$image_return = 3;
$hashtag = "bodypiercing";
$user_search = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/self/media/recent?access_token=".$access_token);
$user_id = $user_search->data[0]->id; // or use string 'self' to get your own media
$return = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/tags/".$hashtag."https://stackoverflow.com/users/self/media/recent?access_token=".$access_token."&count=".$image_return);
// var_dump($return); // if you want to display everything the function returns
foreach ($return->data as $post) {
echo '<div class="col-sm-12 col-md-4 mb-3 text-center">
<a href="'.$post->link.'" target="_blank">
<img src="' . $post->images->standard_resolution->url . '" class="img-fluid img-thumbnail bx-shadow"/>
</a>
<p><i class="fa fa-tag" aria-hidden="true"></i> ' . $post->caption->text . '<br><i class="fa fa-heart" aria-hidden="true"></i> '.$post->likes->count.' <i class="fa fa-comment" aria-hidden="true"></i> '.$post->comments->count.'<br><i class="fa fa-clock-o" aria-hidden="true"></i> ' . date('M j, Y', $post->created_time) . '</p>
</div>';
}
그러나이 결과는 다음과 : 여기
는 전체 코드입니다Notice: Trying to get property of non-object in /home/jesse666toxik/public_html/php/index.main.php on line 42
Warning: Invalid argument supplied for foreach() in /home/jesse666toxik/public_html/php/index.main.php on line 42
이? var_dump
의
결과 :
Notice
: Undefined property: stdClass::$data in
/home/jesse666toxik/public_html/php/index.main.php
on line
37
Notice
: Trying to get property of non-object in
/home/jesse666toxik/public_html/php/index.main.php
on line
37
NULL
Notice
: Trying to get property of non-object in
/home/jesse666toxik/public_html/php/index.main.php
on line
42
Warning
: Invalid argument supplied for foreach() in
/home/jesse666toxik/public_html/php/index.main.php
on line
42
'var_dump ($ return)'의 주석 처리를 제거하십시오. 반환되는 것은 무엇입니까? 여러분의 코드는 배열을 포함하는'data' 매개 변수를 가진 객체가 될 것으로 기대합니다. 그럴까요? – ceejayoz
'$ return' 변수가 사용자를 반환하는 것처럼 보입니다. api 호출은'$ user_search'에 사용 된 것과 같습니다. –
@ceejayoz'var_dump' 결과를 편집하고 포함했습니다. @MacroMan은 원래 튜토리얼의 예제였습니다. 왜 그런지는 모르겠지만 효과가 있습니다. –