当我尝试使用soundcloud api(http://api.soundcloud.com/users/mezomefans.json?consumer_key=xxxxxxxxxx)时,它会提供数据
{"id":153870451,"kind":"user","permalink":"mezomefans","username":"mezomefans","last_modified":"2017/05/15 18:45:01 +0000","uri":"https://api.soundcloud.com/users/153870451","permalink_url":"http://soundcloud.com/mezomefans","avatar_url":"https://i1.sndcdn.com/avatars-000280458917-j6ilmo-large.jpg","country":null,"first_name":"","last_name":"","full_name":"","description":null,"city":"","discogs_name":null,"myspace_name":null,"website":null,"website_title":null,"track_count":1,"playlist_count":0,"online":false,"plan":"Free","public_favorites_count":28,"followers_count":9,"followings_count":12,"subscriptions":[],"reposts_count":0}
但是当我尝试使用php时,它给了我空白页,却没有提供任何数据
我的代码是:
<?php
$url = file_get_contents("http://api.soundcloud.com/users/mezomefans.json?consumer_key=xxxxxxxxxx");
preg_match("'\"followers_count\":(.*?),'si", $url, $matches);
$followers = preg_replace("/[^0-9]/", "", $matches[1]);
echo $followers;
?>
任何想法如何通过php检索数据吗?
答案 0 :(得分:0)
那是旧的users
端点,您应该使用/users/{USER_ID}
端点。
首先,获取用户的用户ID(153870451)。
然后,构建您的请求:
HTTP GET: http://api.soundcloud.com/users/153870451?client_id={CLIENT_ID}
响应:
{
"id": 153870451,
"kind": "user",
"permalink": "mezomefans",
"username": "mezomefans",
"last_modified": "2017/05/15 18:45:01 +0000",
"uri": "https://api.soundcloud.com/users/153870451",
"permalink_url": "http://soundcloud.com/mezomefans",
"avatar_url": "https://i1.sndcdn.com/avatars-000280458917-j6ilmo-large.jpg",
"country": null,
"first_name": "",
"last_name": "",
"full_name": "",
"description": null,
"city": "",
"discogs_name": null,
"myspace_name": null,
"website": null,
"website_title": null,
"track_count": 1,
"playlist_count": 0,
"online": false,
"plan": "Free",
"public_favorites_count": 28,
"followers_count": 9,
"followings_count": 12,
"subscriptions": [],
"reposts_count": 0
}