douyang2530 2014-02-19 12:51
浏览 38
已采纳

错误您最近提出了太多请求。 请冷静。 在Asana API中

I have tried to send only 5 call to fetch tasks from Asana API. Here is my code

$tasks = $client->fetch('https://app.asana.com/api/1.0/workspaces.json');
print_r($tasks);
$i=0;

while(isset($tasks['result']['data'][$i]['id']))
{ 
    $tasks_detail = $client->fetch('https://app.asana.com/api/1.0/workspaces/'.$tasks['result']['data'][$i]['id'].'.json');
    print_r($tasks_detail);

    while(isset($tasks_detail['result']['data'][$i]['id']))
    { 
        $tasks_details = $client->fetch('https://app.asana.com/api/1.0/tasks/'.$tasks_detail['result']['data'][$i]['id'].'.json');
        print_r($tasks_details);
        $i++;
    }

I have used only 2 while loops to fetch tasks from the API after which the api doesn't respond to the calls.

  • 写回答

1条回答 默认 最新

  • douge7771 2014-02-19 13:27
    关注

    Consider this situation:

    $tasks['result']['data'][$i]['id']
    

    exists and

    $tasks_detail['result']['data'][$i]['id']
    

    does not exist.

    You will loop forever since the $i never gets bigger; Consider this situation:

    $tasks['result']['data'][1]['id']
    

    exists and

    $tasks_detail['result']['data'][1]['id']
    $tasks_detail['result']['data'][2]['id']
    $tasks_detail['result']['data'][3]['id']
    

    exists.

    next loop you will access

    $tasks['result']['data'][4]['id']
    

    directly and lose

    $tasks['result']['data'][2]['id']
    $tasks['result']['data'][3]['id']
    

    .

    You may want to do something like this:

    while(isset($tasks['result']['data'][$i]['id'])){ 
        $tasks_detail = $client->fetch('https://app.asana.com/api/1.0/workspaces/'.$tasks['result']['data'][$i]['id'].'.json');
        print_r($tasks_detail);
    
        if(isset($tasks_detail['result']['data'][$i]['id'])){
            $tasks_details = $client->fetch('https://app.asana.com/api/1.0/tasks/'.$tasks_detail['result']['data'][$i]['id'].'.json');
            print_r($tasks_details);
        }
        $i++;
    }
    

    Please be careful to end the loop when you use while loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)