flyingflapjack
flyingflapjack

Reputation: 11

cURL issues with Google Voice "APIs" running on XAMPP/Windows 7

I'm using aaronpk's Google Voice APIs to send and receive SMS messages in Google Voice. I've uncommented the "extension=php_curl.dll" line in the php.ini and have confirmed that cURL is working. I'm now stuck at this point and I keep receiving this error:

Uncaught exception 'Exception' with message 'Could not parse for GALX token'

I've checked all the basic things. The username and password on the account are correct. The only thing that I can see is that cURL is not writing cookie files.

I know the script has a Linux path for the cookiejar / cookiefile by default. I've tried changing this to a Windows directory, as well as including the full path. The code snippet I'm currently using is:

$this->_cookieFile = dirname(__FILE__) . "\cookies.txt";

Even with this code modification, the script is not writing to the cookies.txt file.

I've uploaded these scripts to a Linux host and they work just fine, proving to me that this is a Windows issue. Sadly, we don't have a Linux server for the production environment.

I'm looking for any guidance to get this working within Windows. Right now I'm developing on a Windows 7 machine running XAMPP. The production environment will likely be Windows 2008 Server.

Any assistance would be greatly appreciated!

Upvotes: 1

Views: 1374

Answers (2)

QuickDanger
QuickDanger

Reputation: 1112

It seems that Google has just changed the output HTML for https://accounts.google.com/ServiceLogin in a way that breaks aaronpk's API. I observed the change sometime after December 8th, 2015.

The old HTML: <input name="GALX" type="hidden" value="SecureTokenHere">

The new HTML: <input type="hidden" name="GALX" value="SecureTokenHere">

So if you have the Could not parse for GALX token error, simply update your RegEx from:/name="GALX"\s*type="hidden"\s*value="([^"]+)"/ to /type="hidden"\s*name="GALX"\s*value="([^"]+)"/, or for compatibility, check for the new way if the old way doesn't find a match.

Upvotes: 1

Derek F
Derek F

Reputation: 135

I know this one is rather old...but it's still nice to share an answer, yeah?

Changing the path of the cookie file is good, but the problem here is with cURL trying (and failing) to verify google's SSL certificate. Two solutions can be found here (I found that link in the accepted answer for this other SO question)

For testing purposes I'd think it would be ok to use the quick and dirty solution (blindly accepting all SSL certificates without verifying). You'd insert the following line into the GoogleVoice class constructor along with the other curl_setopt lines

curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, FALSE);

For production code, I'd verify the certificate. Finding and saving the certificate is covered in the first link I provided. Assuming the certificate is in the same directory as GoogleVoice.php, you'd insert the following lines

curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->_ch, CURLOPT_CAINFO, getcwd().'\BuiltinObjectToken-VerisignClass3PublicPrimaryCertificationAuthority.crt');

I'm no cURL expert, so I can't say if there's another way to verify the SSL certificate (or why it isn't needed on a Linux host.) This should be all that needs to be changed to get aaronpk's Google Voice API working on XAMPP

Upvotes: 1

Related Questions