Instagram post URL
Instagram post URL
我有一个非常简单的脚本可以帮助我在我的网站上显示 IG 图片并且效果很好,但理想情况下我希望一旦点击图片就会 link 到实际 post页面而不是图像源。有什么办法可以调整吗?
PS:我知道如何去掉 link 中的 fancybox - 但我不知道如何以及在何处检索实际的 post id / link 来自.
这是我当前的代码:
<?php
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 = 'my access token ';
$username = 'my username';
$user_search = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token);
// $user_search is an array of objects of all found users
// we need only the object of the most relevant user - $user_search->data[0]
// $user_search->data[0]->id - User ID
// $user_search->data[0]->first_name - User First name
// $user_search->data[0]->last_name - User Last name
// $user_search->data[0]->profile_picture - User Profile Picture URL
$limit = 8;
$i = 0;
// $user_search->data[0]->username - Username
$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/" . $user_id . "/media/recent?access_token=" . $access_token);
//var_dump( $return ); // if you want to display everything the function returns
foreach ($return->data as $post) {
echo '<a href="' . $post->images->standard_resolution->url . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
}
?>
实际上你 link 打算 $post->images->standard_resolution->url
现在,如果我们看一下 API returns (https://www.instagram.com/developer/endpoints/users/)
},
"link": "http://instagr.am/p/BWrVZ/",
"user": {
"username": "kevin",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"created_time": "1296710327",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_7.jpg",
"width": 612,
"height": 612
}
如您所见,在顶部有 link
- 您所要做的就是将 href 更改为此 link 而不是图像 URL.
所以改变:
echo '<a href="' . $post->images->standard_resolution->url . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
至:
echo '<a href="' . $post->link . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
它应该可以工作。希望它有所帮助。
我有一个非常简单的脚本可以帮助我在我的网站上显示 IG 图片并且效果很好,但理想情况下我希望一旦点击图片就会 link 到实际 post页面而不是图像源。有什么办法可以调整吗?
PS:我知道如何去掉 link 中的 fancybox - 但我不知道如何以及在何处检索实际的 post id / link 来自.
这是我当前的代码:
<?php
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 = 'my access token ';
$username = 'my username';
$user_search = rudr_instagram_api_curl_connect("https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token);
// $user_search is an array of objects of all found users
// we need only the object of the most relevant user - $user_search->data[0]
// $user_search->data[0]->id - User ID
// $user_search->data[0]->first_name - User First name
// $user_search->data[0]->last_name - User Last name
// $user_search->data[0]->profile_picture - User Profile Picture URL
$limit = 8;
$i = 0;
// $user_search->data[0]->username - Username
$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/" . $user_id . "/media/recent?access_token=" . $access_token);
//var_dump( $return ); // if you want to display everything the function returns
foreach ($return->data as $post) {
echo '<a href="' . $post->images->standard_resolution->url . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
}
?>
实际上你 link 打算 $post->images->standard_resolution->url
现在,如果我们看一下 API returns (https://www.instagram.com/developer/endpoints/users/)
},
"link": "http://instagr.am/p/BWrVZ/",
"user": {
"username": "kevin",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_3_75sq_1295574122.jpg",
"id": "3"
},
"created_time": "1296710327",
"images": {
"low_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_6.jpg",
"width": 306,
"height": 306
},
"thumbnail": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_5.jpg",
"width": 150,
"height": 150
},
"standard_resolution": {
"url": "http://distillery.s3.amazonaws.com/media/2011/02/02/6ea7baea55774c5e81e7e3e1f6e791a7_7.jpg",
"width": 612,
"height": 612
}
如您所见,在顶部有 link
- 您所要做的就是将 href 更改为此 link 而不是图像 URL.
所以改变:
echo '<a href="' . $post->images->standard_resolution->url . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
至:
echo '<a href="' . $post->link . '" class="fancybox"><img src="' . $post->images->standard_resolution->url . '" /></a>';
它应该可以工作。希望它有所帮助。