I was trying to lookup carrier of a phone number using Twilio PHP SDK.
However, I was getting certification error.
I am not sure what I am doing wrong.
If anyone can give me advice, I really appreciate!
Thank you.
$lookup_client = new Lookups_Services_Twilio( $this->twilio_sid, $this->twilio_token );
$number = $lookup_client->phone_numbers->get(
'1-416-333-1111',
array(
'Type' => 'carrier',
"CountryCode" => "US",
)
);
echo $number->carrier;
Services_Twilio_TinyHttpException: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in twilio-php\Services\Twilio\TinyHttp.php on line 119
I made this a while ago. I also made it where you can raw input the phone number. hope it helps!
import sys
import os
from twilio.rest.lookups import TwilioLookupsClient
try:
client = TwilioLookupsClient()
phone = raw_input (" Enter The Targets Phone Number: ")
number = client.phone_numbers.get((phone), include_carrier_info=True, )
print(number.carrier['name'])
print(number.carrier['type'])
except:
print ("Error While Handling Phone Number")
Related
I use twilio/sdk package, with the following code.
$sid = "AC3###############";
$token = "100################";
$from = $to = "+628********99";
$otp = rand(1111111, 9999999);
$client = new Twilio\Rest\Client($sid, $token);
$message = $client
->messages
->create($to, [
'from' => $to,
'body' => 'OTP code : ' . $otp
])
This is the error that I got
Twilio\Exceptions\RestException [HTTP 400] Unable to create record: The 'To' number +628********99 is not a valid phone number.
What did I do wrong ?
How can I use my trial account to send trial sms?
FYI the number I used is a verified number in Twilio and country origin is Indonesia +62.
The line $token = '100################; is missing it's closing single quote. Could that be the reason?
PS: It's hard to build SMS OTP right because of fraud schemes like SMS Traffic Pumping Fraud. Twilio Verify has built-in protection against these risks.
Getting an error that phone number is not verified when I add a callerId.
When placing a call it returns:
Fatal error: Uncaught Twilio\Exceptions\RestException: [HTTP 400]
Unable to create record: The source phone number provided, XXXX, is
not yet verified for your account.
The strange part is that it only gives this error when callerId value is set.
So for example
$call = $client->calls
->create(
"+x", // to
"+x", // from
[
"url" => "http://demo.twilio.com/docs/voice.xml",
]
);
Does work
but the following produces that error.
$call = $client->calls
->create(
"+x", // to
"+x", // from
[
"url" => "http://demo.twilio.com/docs/voice.xml",
"callerId" => 'SomeValue',
]
);
The only difference is that callerId gets set.
From number was purchased, account is not trial and SID is valid since it works without callerId field
Error is returned because it looks like Twilio is trying to use the value of callerId as the phone number. So it looks like you can't set a caller ID in the form of a word, it has to be a numeric value
I'm sorry the docs are not clear about this, but CallerId works the
same a From. It must be Twilio phone number or verified non-Twilio
phone number in your account. It cannot be a word or name. Twilio
phone numbers do not support CNAM (caller name) database entries, so
it is not possible to specify a name that the call recipient sees, if
their carrier does CNAM lookups.
When you specify From, you do not need to pass CallerId.
I have been using pushbullet in the software R (RPushbullet package) to message me when a script finishes. It worked nicely with my notebook and Iphone, however, with the workstation it is not working. The followiing message is returned:
Warning message:
400: Bad Request - Usually this results from missing a required parameter.
I have installed pushbullet in three devices: my workstation, my personal notebook and in my Iphone.
From this, I have observed some things that can be related to the problem: 1) The Access Token is lost every time I restart a session in my online account; 2) Although the setup return a valid key message from my .rpushbullet.json file after the configuration, the API key cannot be retrieved by another code.
My R script:
> require(RPushbullet)
> require(jsonlite)
> pbSetup() #Creating my setup to "~/.rpushbullet.json" file
Please enter your API key (aka 'Access Token': "my API key"
[1] "1. iPhone de XXXXX"
[1] "2. XXXXX"
Select a default device (0 for none): 1
> pbValidateConf(conf = "~/.rpushbullet.json")
key is VALID
device XXX is VALID
device XXX is VALID
[1] TRUE
> pbPost("note", "The R Script worked")
Warning message:
400: Bad Request - Usually this results from missing a required parameter.
> pbGetUser(apikey = .getKey())
Error in .getKey() : could not find function ".getKey"
"my API key" and XXX are valid things that I omitted in the example code
pbPost("note", "The R Script worked")
This code is enough to post to all my devices (when using my notebook), even lacking the other parameters
apparently pbPost() is a little bit picky about the parameter it receives. You need to at least specify type, title and body. As in:
pbPost(type="note", title="testTitle", body="testBody")
If you enter these 3 parameters it should work fine.
Regarding your points 1) and 2), indeed the token is lost and you need to force RPushbullet to read your .json file again. This next workaround works for me, though: I don't create a .json file but instead I pass the key and device id directly to the pbPost().
gimme_a_shout_when_finished = TRUE
if (gimme_a_shout_when_finished){
library(jsonlite)
library(RPushbullet)
my_phone_id = "xxx...myphoneid...xxx"
my_PB_apikey = "xxx...myapikey...xxx"
pbPost(type = "note", title = "my tile", body = "my body",
apikey = my_PB_apikey, devices = my_phone_id, verbose = FALSE,
debug = FALSE)
}
This has been working for me so far. Regarding getting the apikey directly... no ideas for the moment.
Hope this helps.
Twilio newbie using test account. I followed the instructions listed here for installing Twilio php:
https://www.twilio.com/docs/quickstart/php/sms
Because I was getting a certificate error, my host provider suggested I changed the CURLOPT_SSL_VERIFYPEER => false (from true). But now I'm getting this error. How to fix?:
Fatal error: Uncaught exception 'Services_Twilio_RestException' with message 'The requested resource /2010-04-01/Accounts//Messages.json was not found' in
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "ACbxxxxxxx";
$AuthToken = "0cfxxxxxxx";
// Step 3: instantiate a new Twilio Rest Client
//$client = new Services_Twilio($AccountSid, $AuthToken);
$http = new Services_Twilio_TinyHttp(
'https://api.twilio.com',
array('curlopts' => array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,
))
);
$client = new Services_Twilio($sid, $token, "2010-04-01", $http);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+13121111111" => "Curious George",
// "+14158675311" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"929-xxx-xxxx",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
Twilio developer evangelist here.
Firstly, you should never set CURLOPT_SSL_VERIFYPEER to false in production. From the curl manual:
WARNING: disabling verification of the certificate allows bad guys to man-in-the-middle the communication without you knowing it. Disabling verification makes the communication insecure. Just having encryption on a transfer is not enough as you cannot be sure that you are communicating with the correct end-point.
For the sake of getting you going with Twilio though your issue is in the variable names you are using.
At the top of the file you set:
$AccountSid = "ACbxxxxxxx";
$AuthToken = "0cfxxxxxxx";
But when you create a Twilio you use $sid and $token.
$client = new Services_Twilio($sid, $token, "2010-04-01", $http);
If you change those to $AccountSid and $AuthToken it should work as you expected.
We are trying to integrate Google Wallet for digital goods with or php app and 2 days ago, on 15 November we've managed to get it working. However, when checking again the next day and even today, although the code remained the same, we didn't change a letter in it, it is still not working, giving us this error:
Uh oh. There was a problem.
We couldn't complete your purchase because of a technical issue.
Details of the problem below: Unfortunately, we could not confirm your purchase with the merchant's server. Your order has been canceled. Please contact the merchant if this problem continues.
The code we're using is this:
$response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
$response = substr_replace($response, "", 0, 4); //remove "
$response = JWT::decode($response, $sellerSecretKey);
header("HTTP/1.1 200 OK");
and like I said it worked fine two days ago and I have the feeling it's working now also, because in our log file we get printed this response
stdClass Object
(
[iss] => Google
[request] => stdClass Object
(
[name] => Product 1.
[description] => You are purchasing a total of 1 products from our Store. Thank you.
[price] => 9.99
[currencyCode] => USD
[sellerData] => client name,email address
)
[response] => stdClass Object
(
[orderId] => GWDG_S.c7a66f5b-4674-43f0-be16-2b72f69a7445
)
[typ] => google/payments/inapp/item/v1/postback/buy
[aud] => 03083876603093172875
[iat] => 1384689627
[exp] => 1384689647
)
The postback url is correctly specified and we are using sandbox to do the tests.
Is this a problem from Google? Are they working on the software or something and this is what's causing the problem? Or are we doing something wrong here?.
Any help would be much apreciated. Thank you.
Meant to comment but it won't fit...
That error points to something in your Postback handler. I just tried sandbox and things seem fine.
I'm not a php dev so this maybe inaccurate - are you responding to Postback with the orderId? Again, this is only based on my read of the code above (I think I only see http 200?)
The only other thing I can think of is that the lag for you to respond is more than 10 seconds(?) - which could explain why could be another reason you have logged data, but Google still cancelled it.
*Strike through text: you'd get data to log because Google will send you the data, it's whether or not you respond properly that matters
Once you decode the JWT with your Seller Secret, you can make sure that the cake purchase is OK and record it. Within 10 seconds of receiving the postback, your server must send a 200 OK response where the only content is the value of the "orderId" field. If it doesn't, Google cancels the transaction.
REF: https://developers.google.com/commerce/wallet/digital/docs/postback#responding
Hth.