分页在 twilio 通话记录 laravel 中不起作用 [英] Pagination is not working in twilio call logs laravel

查看:28
本文介绍了分页在 twilio 通话记录 laravel 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\ApiController;
use App\Model\User;
use Illuminate\Support\Facades\Validator;
use Auth;
use Twilio\Rest\Client;
use Twilio\TwiML\VoiceResponse;

class TwilioController extends ApiController
{
    public function __construct(){
        $sid = env('TWILIO_SID');
        $token = env('TWILIO_TOKEN');
        $this->twilio = new Client($sid, $token);
        if (request('lang'))
            \App::setLocale(request('lang'));
    }

    public function callLogs(Request $request){
        try{
            $twilioNumber = Auth::user()->twilio_number;
            $calls = $this->twilio->calls
                ->read([], 20);
                $data = [];
                $i = 0;
            foreach($calls as $call){
                $data[$i]['from'] = $call->from;
                $i++;
            }
            $responseData = array('status'=>true, 'message'=>'Data has been returned successfully!', 'data'=>$data);
        } catch (\Exception $e) {
            $responseData = array('status'=>false, 'message'=>$e->getMessage(), 'data'=>[]);
        }
        $res = json_encode($responseData);
        print $res;

    }

当我使用 laravel rest api 在 twilio 中获取通话记录时,分页不起作用.当我使用页面参数时,分页不起作用,它给我保存输出给我的第一页.Postman 参数 - 第 2 页

Pagination is not working when i get call history in twilio using laravel rest api. when i use page parameter with this then pagination is not working it give me save output as given me 1st page. Postman parameters - Page:2

谢谢

推荐答案

我认为 Twilio 的 page() 函数会对您有所帮助.与 read() 一样,它接受一组选项来缩小搜索范围,同时还有一个 pageSize 参数,默认为每页 50 次调用.(我相信最大值是 1000.)

I think Twilio's page() function will help you. Like read(), it accepts an array of options to narrow your search along with a pageSize parameter defaulting to 50 calls per page. (I believe the maximum value is 1000.)

这是一个例子.

//Get all call logs. 20 per page
$calls = $twilio->calls->page( [], 20 );

$data = [];

foreach($calls as $call){
    $data[] = $call->sid;
}

//You can access the previous and next page urls using the resource functions in the calls object return from twilio.

return response()->json(["prev" => $calls->getPreviousPageUrl(), "next" => $calls->getNextPageUrl(), "calls" => $data]);

这篇关于分页在 twilio 通话记录 laravel 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆