Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Soundcloud API检查一个用户是否在跟踪另一个用户_Php_Json_Api_Soundcloud - Fatal编程技术网

Php Soundcloud API检查一个用户是否在跟踪另一个用户

Php Soundcloud API检查一个用户是否在跟踪另一个用户,php,json,api,soundcloud,Php,Json,Api,Soundcloud,我正在尝试使用SoundCloudAPI和php确定一个用户是否在Soundcloud上跟踪另一个用户。 到目前为止,我遇到了一个解决方案,它要么返回一个对象(用户),要么返回一个404错误: $test = json_decode($client->get('/users/{id1}/followers/{id2}')); 我使用不同的用户ID尝试了多次,但始终收到以下错误消息: 'Services_Soundcloud_Invalid_Http_Response_Code_Excep

我正在尝试使用SoundCloudAPI和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尝试了这个片段,我知道肯定存在一个相互的追随者。 对如何解决这个问题有什么建议吗

更新(21.05.15):

我已经阅读了一些Soundcloud文档和cam的代码片段:

<?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(预期输出)
  • 没有输出(我正在跟踪用户)
  • 未捕获异常“服务\u声音云\u无效\u Http\u响应\u代码\u异常”,消息为“请求的URL以Http代码404响应”

  • 第三个选项是指$client->put或$client->delete

    <?php
    require_once 'Services/Soundcloud.php';
    
    $client = new Services_Soundcloud(
    'xxxxxxxxxxxxxxxxxxx160', 'xxxxxxxxxxxxxxxxxx34dd1 ');
    
    $userid     = 1672444;
    $followerid = 383228;
    $yesno = '';
    
    try {
      $response = json_decode($client->get('users/'.$userid.'/followers'), true);
      $yesno = IdInArray($response, $followerid);
      echo $yesno;
    } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
      exit($e->getMessage());
    }
    
    function IdInArray($response, $followerid){
    echo $followerid.'<br/>';
      for($i = 0; $i < count($response); ++$i) {
        if($response[$i]['id'] == $followerid){
          return 'yolo';
        }
        else{
          return 'nolo';
        }
      }
    }
    ?>
    

    我不知道为什么您首先放置和删除同一个用户?我会下载追随者或你关注的人的数组,如果它包含你想要检查的用户ID,我会浏览这个数组。