Hi I keep geting the following error when I try to delete a number from my twilio subaccount using REST API in PHP
my code is;
$number = $twClient->account->incoming_phone_numbers->get($number_Sid);
$twClient->account->incoming_phone_numbers->delete($number->sid);
The error that I am getting is;
[22-Aug-2013 09:40:17 UTC] PHP Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The requested resource was not found' in C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php- 732e6f6\Services\Twilio.php:226
Stack trace:
#0 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php- 732e6f6\Services\Twilio.php(145): Services_Twilio->_processResponse(Array)
#1 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio.php(179): Services_Twilio->_makeIdempotentRequest(Array, '/2010-04-01/Acc...', 1)
#2 C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio\ListResource.php(71): Services_Twilio->deleteData('/2010-04-01/Acc...', Array)
#3 C:\Program Files (x86)\Zend\Apache2\htdocs\testers\web2call\application\controllers\clientphonenos_controller.php(518): Services_Twilio_ListResource->delete('PN397fc000ce6f8...')
#4 [internal function]: ClientPhoneNos_controller->data_form('delete', '+14139926551_AC...')
#5 C:\Program Files (x86)\Zend\Apache2\htdocs\system\core\Cod in C:\Program Files (x86)\Zend\Apache2\htdocs\twilio-twilio-php-732e6f6\Services\Twilio.php on line 226
If you have already successfully deleted the phone number, Twilio will return a 404 Not Found to you, which the PHP library will interpret as a RestException. You can only delete the phone number one time :)
You can override exception by using this syntax:
try
{
// do something that can go wrong
}
catch (Exception $e)
{
throw new Exception( 'Something really gone wrong', 0, $e);
}
Here's another live sample for sending messages with an exception catcher:
<?PHP
require "Services/Twilio.php";
// Set our AccountSid and AuthToken from twilio.com/user/account
$AccountSid = "{ACCOUNTSID}";
$AuthToken = "{AUTHTOKEN}";
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
/* Your Twilio Number or Outgoing Caller ID */
$from = '2126404004';
$people = array("212-716-1130");
$body = "Enter your text message here";
$errorIds = array(); //user ids array which had broken phones
foreach ($people as $to) {
try
{
$client->account->sms_messages->create($from, $to, $body);
echo "Sent message to: $to \n <br>";
}
catch (Exception $e)
{ //on error push userId in to error array
$count++;
array_push($errorIds, $to);
}
}
print_r($errorIds);
?>
Without catching the exception, the script will die with an error like:
<br>PHP Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The message From/To pair violates a blacklist rule.' in /var/www/vhosts/httpdocs/twilio/Services/Twilio.php:149
Related
This is the first time I use parse.com php SDK and I try to execute the following code
<?php require '../autoload.php';
use Parse\ParseObject;
use Parse\ParseClient;
ParseClient::initialize( "Zsr...", "BzM..", "D..." );
$gameScore = new ParseObject("GameScore");
$gameScore->set("score", 1337);
$gameScore->set("playerName", "Sean Plott");
$gameScore->set("cheatMode", false);
try {
$gameScore->save();
echo 'New object created with objectId: ' . $gameScore->getObjectId();
} catch (ParseException $ex) {
// Execute any logic that should take place if the save fails.
// error is a ParseException object with an error code and message.
echo 'Failed to create new object, with error message: ' + $ex->getMessage();
}
?>
But I get that error
Fatal error: Uncaught exception 'Parse\ParseException' with message 'SSL certificate problem: unable to get local issuer certificate' in /opt/lampp/htdocs/parse/src/Parse/ParseClient.php:250 Stack trace: #0 /opt/lampp/htdocs/parse/src/Parse/ParseObject.php(925): Parse\ParseClient::_request('POST', '/1/classes/Game...', NULL, '{"score":1337,"...', false) #1 /opt/lampp/htdocs/parse/src/Parse/ParseObject.php(836): Parse\ParseObject::deepSave(Object(Parse\ParseObject), false) #2 /opt/lampp/htdocs/parse/src/hola.php(11): Parse\ParseObject->save() #3 {main} thrown in /opt/lampp/htdocs/parse/src/Parse/ParseClient.php on line 250
The code it's the tutorial code, iI haven't changed anything anyone knows what's the problem?
I am also getting same issue. Now I resolve using some other forums answer.
Open your ParseClient.php and find:
curl_init();
And after that add line add:
curl_setopt($rest, CURLOPT_SSL_VERIFYPEER, false);
It will work.
When i try to run php code using Parse.com PHP SDK it
the error is "Account already exists for this username"
but it throw all this error message:
Fatal error: Uncaught exception 'Parse\ParseException' with message 'Account already exists for this username' in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php:357 Stack trace: #0 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(1038): Parse\ParseClient::_request('POST', 'classes/_User', NULL, '{"username":"my...', false) #1 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseObject.php(947): Parse\ParseObject::deepSave(Object(Parse\ParseUser), false) #2 /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseUser.php(108): Parse\ParseObject->save() #3 /Users/yousef/Desktop/project/test.php(20): Parse\ParseUser->signUp() #4 {main} thrown in /Users/yousef/Desktop/project/vendor/parse/php-sdk/src/Parse/ParseClient.php on line 357
The Code i Use
<?php
require 'vendor/autoload.php';
use Parse\ParseClient;
ParseClient::initialize('YousefId', '', 'YousefMaster');
ParseClient::setServerURL('server-ip:1337/parse');
use Parse\ParseUser;
$user = new ParseUser();
$user->set("username", "my name");
$user->set("password", "my pass");
$user->set("email", "email#example.com");
$user->set("phone", "415-392-0202");
try {
$user->signUp();
} catch (ParseException $error) {
echo $error->getCode();
echo $error->getMessage();
}
?>
so how do i just show the error code and message instead of showing all this error.
You need to refer to the ParseException within the Parse namespace.
Try
catch (Parse\ParseException $error) {
// ...
}
I am trying to ultimately run and display reports from a remote Jasper Server in a PHP application. What I am trying to do this with is the jrs-rest-php-client project on github.
The error:
Fatal error: Uncaught exception 'Jaspersoft\Exception\RESTRequestException' with message 'An unexpected HTTP status code was returned by the server' in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php:409
Stack trace:
#0 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php(479): Jaspersoft\Tool\RESTRequest->handleError(0, Array, false)
#1 C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Service\ReportService.php(40): Jaspersoft\Tool\RESTRequest->prepAndSend('https://jasper....', Array, 'GET', NULL, true)
#2 C:\xampp\htdocs\jrs\report.php(30): Jaspersoft\Service\ReportService->runReport('/Reports/Distri...', 'html')
#3 {main} thrown in C:\xampp\htdocs\jrs\vendor\src\Jaspersoft\Tool\RESTRequest.php on line 409
My PHP:
require_once __DIR__ . "/vendor/autoload.php";
use Jaspersoft\Client\Client;
$d = new Client(
"http://jasper.server.com/jasperserver-pro",
"username",
"password",
"organization"
);
$info = $d->serverInfo();
Any ideas?
Looking into the code of RESTRequest.php there are two cases in which this exception is thrown:
A JSON result set with an unknown error code is returned (unknown meaning different from 200 OK)
No JSON result set is returned at all
So I suspect the connection isn't working properly. To find out more, you should catch the exception in your code and evaluate it:
It could look something like this (I'm more familiar with Java):
try {
$d = new Client(
"http://jasper.server.com/jasperserver-pro",
"username",
"password",
"organization"
);
$info = $d->serverInfo();
} catch (RESTRequestException $e) {
echo 'RESTRequestException:';
echo 'Exception message: ', $e->getMessage(), "\n";
echo 'Set parameters: ', $e->parameters, "\n";
echo 'Expected status code:', $e->expectedStatusCodes, "\n";
echo 'Error code: ', $e->errorCode, "\n";
}
If there is still an error, you can check the following:
Can you reach the jasper server from the server where this code is deployed? Sometimes e.g. firewall settings can interfere.
Is the organization called exactly like defined in the properties of the organization in the server? (Open repository / right click on organization / properties / resource-id)
I use this code
#!/usr/bin/php
<?php
require_once('whatsapp_whatsapi_config.php');
$destinationPhone = 'xxxx';
$w = new WhatsProt($userPhone,0, $userName, $debug);
$w->Connect();
$w->LoginWithPassword($password);
$message = 'WhatsApp';
$w->Message($destinationPhone, $message);
echo "Mensaje enviado exitosamente";
?>
and this error displayed
PHP Fatal error: Uncaught exception 'LoginFailureException' in /var/www/html/whats/src/whatsprot.class.php:2274
Stack trace:
/var/www/html/whats/src/whatsprot.class.php(552): WhatsProt->doLogin()
/var/www/html/whats/whatsapp_whatsapi_send.php(13): WhatsProt->loginWithPassword('Mu7q0hq/vRSLFCU...')
{main}
thrown in /var/www/html/whats/src/whatsprot.class.php on line 2274
I tried use the WART app but the password generated is incorrect
Add a try-catch clause on the line that has $w->LoginWithPassword($password); and use the getMessage() method on the exception to see what the error message is, and what might be wrong with your login
Uploading a file and immediately do permission->update:
public function sharingFile() {
$fileId = $this->file['id'];
$permissionId = $this->file['userPermission']['id'];
try {
$permission = $this->service->permissions->get($fileId, $permissionId);
$permission->setRole('writer');
$permission->setType('default');
print_r($permission);
return $this->service->permissions->update($fileId, $permissionId, $permission);
} catch (Exception $e) {
return "Error: " . $e;
}
return NULL;
}
and get an error:
Error: exception 'Google_ServiceException' with message 'Error calling PUT
https://www.googleapis.com/drive/v2/files/0B6xE_F1PfpXTbF9IdHgxbEJueEk/permissions/me:
(400) Bad Request' in Z:\home\site.com\www\google-api-php-client\src\io\Google_REST.php:66
Stack trace:
#0 Z:\home\site.com\www\google-api-php-client\src\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 Z:\home\site.com\www\google-api-php-client\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
#2 Z:\home\site.com\www\google-api-php-client\src\contrib\Google_DriveService.php(774): Google_ServiceResource->__call('update', Array)
it may be a bug in the library?
Help, please.
Your code is trying to update permissions for the document owner and make that user a writer instead. A Drive document must have exactly one owner, so your request is invalid.