根據Instagram API Docs,followed_by
是counts
的孩子,它是data
的孩子。
https://api.instagram.com/v1/users/1574083/?access_token=ACCESS-TOKEN
返回:
{
"data": {
"id": "1574083",
"username": "snoopdogg",
"full_name": "Snoop Dogg",
"profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
"bio": "This is my bio",
"website": "http://snoopdogg.com",
"counts": {
"media": 1320,
"follows": 420,
"followed_by": 3410
}
}
下因此應工作。
<?php
$url = 'https://api.instagram.com/v1/users/XXXX?access_token=XXXX';
$api_response = file_get_contents($url);
$record = json_decode($api_response);
echo $record->data->counts->followed_by;
// if nothing is echoed try
echo '<pre>' . print_r($api_response, true) . '</pre>';
echo '<pre>' . print_r($record, true) . '</pre>';
// to see what is in the $api_response and $record object
我剛剛嘗試過你給出的代碼,但它不起作用(我已經嘗試了兩個echo自己)。我甚至確保我的api.instagram.com/xxx是有效的,它是。 –
@NazarAbubaker - 你確定你的access_token是正確的 - 你是如何生成它的?嘗試上面編輯的代碼,並讓我們知道API實際返回的內容。 – PassKit
我用它來生成access_token [link] http://jelled.com/instagram/access-token [/ link]。從[鏈接] http://stackoverflow.com/questions/12677551/how-to-get-access-token-from-instagram-token-using-jquery-or-php [/鏈接]採取 我得到的是「警告:file_get_contents()[function.file-get-contents]:無法找到包裝" https:" - 您忘了在配置PHP時啓用它嗎?在XXX上第36行」 –