循环中有多个cURL请求

时间:2014-12-06 13:26:20

标签: php curl

我有一个代码顶部从API获取呼叫列表。我收到数据并将其放在表格中。收到的数据包括:来电,来电,日期和来电ID。

现在我将数据放入表中,并添加一个附加字段以播放呼叫记录。现在,我必须向第二个API提出另一个请求以及上一个请求中收到的CALL ID。  流程图是: enter image description here

我的代码如下所示:

    $post_url = "https://api.plivo.com/v1/Account/MANDE1OGM2ZGQ5ZDIWOD/Call/?from_number=".$numberOfCaller;

     $AuthID = "MANDE1OGM2ZZXXXXXXXX" ;
     $AuthToken = "MjE2ZmRjY2FjZWE4ZWE4ZWM0NmNkXXXXXXXX";
    $curl = curl_init($post_url);

    $headers = array(
            'Content-Type: application/json'
            );
    curl_setopt($curl, CURLOPT_USERPWD, "$AuthID:$AuthToken");
    curl_setopt($curl, CURLOPT_URL, $post_url);

    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
    $post_response = curl_exec($curl); 

    $post_response=json_decode($post_response);

?>

<tr>
<td><div class="grid_heading">Call From</div></td>
<td><div class="grid_heading">Call To</div></td>
<td><div class="grid_heading">Call Date/Time</div></td>
<td><div class="grid_heading">Play</div></td>

<?php foreach($post_response->objects as $call){
                        //echo "<pre>";
                        //print_r($call); ?>

                        <tr>
                            <td><div class="grid_content editable"> <?php echo $call->from_number; ?>      </div></td>
                            <td><div class="grid_content editable"> <?php echo $call->to_number; ?>        </div></td>
                            <td><div class="grid_content editable"> <?php echo $call->call_duration; ?>    </div></td>
                            <td><div class="grid_content editable"> <?php echo $call->total_amount; ?>     </div></td>

<!-- My Second cURL request goes here that will fetch Call ID from previous Request's result and make a new request based on the same -->

<?php

   $audioLink = $plivocalls->call_uuid;         // The CALL ID that was fetched


 $ch = curl_init('https://api.plivo.com/v1/Account/'.$auth_id.'/Recording/?call_uuid='.$call->call_uuid); 
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 #curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json');
 curl_setopt($ch, CURLOPT_USERPWD, "$auth_id:$auth_token");
 $result = curl_exec($ch);
 //echo ($result);
 curl_close($ch);

//echo "<pre>";
//print_r($result);
foreach($result->objects as $plivocalls){

// I need only one output that is 'recording URL'

   $recordLink = $plivocalls->recording_url;
   //echo $recordLink;

 ?> 

<td>
 <img id="playonclick" rel="<?php echo $recordLink; ?>"  src="../images/play_icon.png" alt="Play Call" title="Play Call" />
</td>

<?php } ?>             <!-- Closing ForEach for second request -->

</tr>

<?php } ?>             <!-- Closing ForEach for initial request -->

现在我正在完成第一个和第二个请求。但我的疑问是,当我提出FIRST请求时,我会收到一些结果。我必须获取一个结果值并发送SECOND请求并获得将在最后一个循环的结果。

0 个答案:

没有答案