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.

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

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题