【发布时间】:2015-08-02 05:12:09
【问题描述】:
我正在尝试确定用户是否使用 Soundcloud API 和 php 在 Soundcloud 上关注另一个用户。 到目前为止,我遇到了一个解决方案,它要么返回对象(用户),要么返回 404 错误:
$test = json_decode($client->get('/users/{id1}/followers/{id2}'));
我用不同的用户 ID 多次尝试,但总是收到以下错误消息:
'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 404.'
我知道这应该是通知我 user2 没有关注 user1 的错误消息。但是,我已经尝试了这个带有 id 的 sn-p,我知道肯定存在互惠的追随者。 有关如何解决此问题的任何建议?
更新 (21.05.15):
我已经阅读了一些 Soundcloud 文档并通过了一段代码 sn-p:
<?php
require_once 'Services/Soundcloud.php';
// create a client object with access token
$client = new Services_Soundcloud('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET');
$client->setAccessToken('YOUR_ACCESS_TOKEN');
// Follow user with ID 3207
$client->put('/me/followings/3207');
// Unfollow the same user
$client->delete('/me/followings/3207');
// check the status of the relationship
try {
$client->get('/me/followings/3207');
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
if ($e->getHttpCode() == '404')
print "You are not following user 3207\n";
}
?>
这几乎就是我所指的。但是,如果我用这个脚本打开一个 php 页面,结果总是以下三种情况之一:
- 您没有关注用户 3207(预期输出)
- 没有输出(我在关注用户)
- 未捕获异常“Services_Soundcloud_Invalid_Http_Response_Code_Exception”,并带有消息“请求的 URL 以 HTTP 代码 404 响应。”
第三个选项是指 $client->put 或 $client->delete
【问题讨论】:
-
我不知道你为什么先把和删除同一个用户?如果它包含您要检查的用户 ID,我会下载您关注的关注者或人的数组并遍历该数组。
标签: php json api soundcloud