Google Voice“API”的 cURL 问题在 XAMPP/Windows 7 上运行

发布于 2024-10-03 01:05:25 字数 775 浏览 3 评论 0原文

我使用 aaronpk 的 Google Voice API 在 Google Voice 中发送和接收短信。我已取消注释 php.ini 中的“extension=php_curl.dll”行,并确认 cURL 正在工作。我现在被困在这一点上,并且不断收到此错误:

未捕获的异常“异常” 消息“无法解析 GALX” 令牌'

我已经检查了所有基本的事情。帐户的用户名和密码正确。我唯一能看到的是 cURL 没有写入 cookie 文件。

我知道该脚本默认有一个 cookiejar / cookiefile 的 Linux 路径。我尝试将其更改为 Windows 目录,并包含完整路径。我当前使用的代码片段是:

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

即使进行了此代码修改,脚本也不会写入 cookies.txt 文件。

我已将这些脚本上传到 Linux 主机,它们工作得很好,向我证明这是一个 Windows 问题。遗憾的是,我们没有用于生产环境的 Linux 服务器。

我正在寻找任何指导来使其在 Windows 中运行。现在我正在运行 XAMPP 的 Windows 7 计算机上进行开发。生产环境可能是Windows 2008 Server。

任何帮助将不胜感激!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-10-10 01:05:25

我知道这个已经很旧了......但分享答案仍然很高兴,是吗?

更改 cookie 文件的路径很好,但这里的问题是 cURL 尝试(但失败)验证 google 的 SSL 证书。可以找到两种解决方案 这里(我在接受的答案中找到了该链接对于另一个SO问题

出于测试目的,我认为使用快速而肮脏的解决方案(盲目接受所有SSL证书而不进行验证)是可以的。
您将以下行与其他curl_setopt 行一起插入到GoogleVoice 类构造函数中。

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

对于生产代码,我将验证证书。我提供的第一个链接中介绍了查找和保存证书。假设证书与 GoogleVoice.php 位于同一目录中,您需要插入以下几行

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');

我不是 cURL 专家,所以我不能说是否有其他方法来验证 SSL 证书(或者为什么不需要它)在 Linux 主机上。)这应该是让 aaronpk 的 Google Voice API 在 XAMPP 上工作所需的全部更改

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

像你 2024-10-10 01:05:25

Google 似乎刚刚更改了 https://accounts.google.com/ServiceLogin 的输出 HTML,其方式破坏了 aaronpk 的 API。我在 2015 年 12 月 8 日之后的某个时间观察到了这一变化。

旧的 HTML:

新的 HTML:< ;input type="hidden" name="GALX" value="SecureTokenHere">

因此,如果您遇到 Could not parse for GALX token 错误,只需从以下位置更新您的正则表达式:<代码>/name="GALX"\s*type="hidden"\s*value="([^"]+)"/ 到 /type="hidden"\s*name= "GALX"\s*value="([^"]+)"/,或者为了兼容性,如果旧方式找不到匹配项,请检查新方式。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文