【问题标题】:Pagination is not working in twilio call logs laravel分页在 twilio 调用日志 laravel 中不起作用
【发布时间】:2020-04-28 16:29:04
【问题描述】:
<?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 页

谢谢

【问题讨论】:

    标签: twilio twilio-api twilio-php twilio-twiml


    【解决方案1】:

    我认为 Twilio 的 page() 功能会对您有所帮助。与read() 一样,它接受一系列选项来缩小搜索范围以及默认为每页50 次调用的pageSize 参数。 (我相信最大值是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]);
    

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 1970-01-01
      • 2014-08-15
      • 2013-09-09
      • 1970-01-01
      • 2016-11-28
      • 2013-01-05
      • 2019-04-29
      • 1970-01-01
      相关资源
      最近更新 更多