Objective c Twilio可编程语音isn';行不通
当我尝试使用Objective c Twilio可编程语音isn';行不通,objective-c,twilio,twilio-api,twilio-php,twilio-twiml,Objective C,Twilio,Twilio Api,Twilio Php,Twilio Twiml,当我尝试使用[TwilioVoice Call]方法从应用程序传递参数时,我无法在twiML应用程序上获取这些参数。但是,当我尝试使用FormData从邮递员传递相同的数据时,它工作正常,并且能够成功地创建呼叫 您能帮助我如何使用从iOS应用程序传递到twiML的param吗 PHP中的TwiML应用程序: <?php /* * Makes a call to the specified client using the Twilio REST API. */ include('./v
[TwilioVoice Call]
方法从应用程序传递参数时,我无法在twiML应用程序上获取这些参数。但是,当我尝试使用FormData从邮递员传递相同的数据时,它工作正常,并且能够成功地创建呼叫
您能帮助我如何使用从iOS应用程序传递到twiML的param吗
PHP中的TwiML应用程序:
<?php
/*
* Makes a call to the specified client using the Twilio REST API.
*/
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_GET["to"]) ? $_GET["to"] : "";
if (!isset($to) || empty($to)) {
$to = isset($POST["to"]) ? $_POST["to"] : "";
}
$from = isset($_GET["from"]) ? $_GET["from"] : "";
if (!isset($from) || empty($from)) {
$from = isset($POST["from"]) ? $_POST["from"] : "";
}
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
self.call = [TwilioVoice call:[self fetchAccessToken]
params:@{@"to": @"1",@"from":@"2"}
uuid:uuid
delegate:self];
当我尝试从iOS传递参数时,会出现IO错误日志
警告-13224拨号:Twilio不支持拨打此号码或该号码无效
参考TwiML应用程序代码
这里是Twilio开发者福音传道者 原因是Twilio无法解析从服务器返回的TwiML。在本例中,这是因为您的PHP没有返回TwiML,而是试图返回TwiML 它应该返回一个带有嵌套的。您也可以使用帮助器库来构建它。尝试将代码更改为:
<?php
include('./vendor/autoload.php');
include('./config.php');
$to = isset($_REQUEST["To"]) ? $_REQUEST["To"] : "";
$to = str_replace("client:", "", $to);
$from = isset($_REQUEST["From"]) ? $_REQUEST["From"] : "";
use Twilio\Twiml;
$response = new Twiml();
$dial = $response->dial(['callerId' => $from]);
$dial->client($to);
echo $response;
第1步。在名称中,您必须传递用户的名称(任何您想要的内容)
第二步。您需要使用3个参数生成令牌
第三步。您需要创建VoiceGrant的对象
第四步。你需要通过身份证
第五步。您需要设置从twilio生成的推送通知Id
$name = $this->input->post('name');
//$PUSH_CREDENTIAL_SID = 'CRaf1a66dd4a7656876e16c7820ef5c01e';
$outgoingApplicationSid = 'APf9b1b789ba690b8789d95a42511f2018';
// choose a random username for the connecting user
$identity = $name;
// Create access token, which we will serialize and send to the client
$token = new AccessToken(
$this->twilioAccountSid,
$this->twilioApiKey,
$this->twilioApiSecret,
3600,
$identity
);
// $chatGrant = new ChatGrant( $pushCredentialSid= "CRaf1a66dd4a7656876e16c7820ef5c01e");
//
// print_r($chatGrant);die;
// Create Chat grant
// $voiceGrant = new VoiceGrant($serviceSid = 'IS840a7e5f64634ab6bf179c3f8b0adfc4',$pushCredentialSid = 'CRaf1a66dd4a7656876e16c7820ef5c01e');
$voiceGrant = new VoiceGrant();
$voiceGrant->setOutgoingApplicationSid($outgoingApplicationSid);
// Optional: add to allow incoming calls
$voiceGrant->setIncomingAllow(true);
$voiceGrant->setPushCredentialSid('CRaf1a66dd4a7656876e16c7820ef5c01e');
// Add grant to token
$token->addGrant($voiceGrant);
// render token to string
$voice_token = $token->toJWT();
if($voice_token){
$data['token'] = $voice_token;
$this->response = array('status'=>1,'data'=>$data);
}else{
$this->response = array('status'=>0,'message'=>'Not found');
}
感谢您的回复,我尝试了相同但仍然相同的错误,看看我上面更新的代码。您是否能够向PHP应用程序发出请求并查看返回的XML?这可能有助于指出错误所在。呸,我刚刚看到了我的错误。等等,需要更新答案中的代码。好的,更正了。它在$dial
附近。再看一看,让我知道这是否有效。是的,当然,非常感谢您提供的信息,请检查步骤