Closed chrisjchrisj closed 6 years ago
Hey @chrisjchrisj,
You need to add quotes around your API key and secret like so:
$basic = new \Nexmo\Client\Credentials\Basic("NEXMO_API_KEY", "NEXMO_API_SECRET");
Alternatively, you can define NEXMO_API_KEY
and NEXMO_API_SECRET
as constants instead
Thanks for your reply. When I follow your instructions and "add quotes around your API key and secret" I see this error: Parse error: syntax error, unexpected 'composer' (T_STRING), expecting variable (T_VARIABLE) or '$' in /home/....com/index0.php on line 3 I don't know how to "define NEXMO_API_KEY and NEXMO_API_SECRET as constants instead", so any additional help will be appreciated.
I'm working with Chris in the Nexmo Community Slack channel
Hello,
I am simply trying to set up a nexmo sms send/receive page in php. I have pasted the code below, into a file named index0.php and then entered my API key and API secret. But when I view the page in the browser I see this error:
Parse error: syntax error, unexpected 'composer' (T_STRING), expecting variable (T_VARIABLE) or '$' in /home/........com/index0.php on line 3
Any help will be appreciated.
` <?php
$ composer require nexmo/client
$basic = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET); $client = new \Nexmo\Client($basic);
$cmd = 'https://rest.nexmo.com/sms/json';
echo "aqui ----a $cmd \n";
$CAMPOS = array ( 'from' => 'aaa', 'text' => 'test', 'to' => '', 'api_key' => '', 'api_secret' => '' );
//Encode the array into JSON. $JSONCAMPOS = json_encode($CAMPOS);
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $cmd); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch,CURLOPT_POSTFIELDS, $JSONCAMPOS);
$output = curl_exec($ch); curl_close($ch);
echo "\n"; echo $output; echo "\n";
?>`