Thursday, December 3, 2009

I use google voice with php

I have figured out how to send make a php page use my google voice web widget dynamically! I wanted to pull numbers out of a database to call if I wanted to instead of just using it manually. I could call someone at any time programatically and they would pick up the phone and wonder who was calling them and it would be my voice mail giving them my custom message or I could tell it to call me if I want to talk to them when they pick up. I could use it to talk to someone that has a busy phone and as soon as they actually pick up it will call me. here is the php code I used to make it call someone to call me.

it worked great!! I got it to work with the php code and each time I refresh the page it calls again. This is nice!

$url = 'https://clients4.google.com/voice/embed/webButtonConnect';
//person wanted to call me
$phone = '2089991234';
$postVars = array(
'showCallerNumber' => '1',
'callerNumber' => "$phone",
'buttonId' => '9ea ... 91d3166',
'name' => 'mike'
);
$t = http_build_query($postVars);

$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($postVars));
curl_setopt($ch,CURLOPT_POSTFIELDS,$t);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>