需要帮助使用 cURL 将书签添加到 Delicious
我正在尝试编写一个可以向我的 Delicious 帐户添加书签的类。
这是我的方法:
public function addBookmark($url, $description) {
$dusername = 'myUsername';
$dpassword = 'myPassword';
$api = 'api.del.icio.us/v1';
$link = urlencode($url);
$desc = urlencode($description);
$apicall = "https://$dusername:$dpassword@$api/posts/add?&url=$link&description=$desc";
$ch = curl_init($apicall);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, 'php - curl');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
}
在实际代码中,$dusername 和 $dpassword 是我的实际凭据。
从 PHP 调用时,无法添加书签。但是,如果我 echo $apicall,并直接使用 FireFox 转到它,则会添加书签。所以,这让我假设我的 cURL 实现中有错误。我尝试注释掉设置 CURLOPT_SSL_VERIFYHOST
和 CURLOPT_USERAGENT
的行,但这也不起作用。
这让我发疯,因为一开始我编写了自己的代码,但它不起作用。现在我正在使用某人(据称)为自己工作的代码,但仍然没有运气。
非常感谢任何帮助,谢谢!
I'm trying to write a class that can add a bookmark to my Delicious account.
Here's my method:
public function addBookmark($url, $description) {
$dusername = 'myUsername';
$dpassword = 'myPassword';
$api = 'api.del.icio.us/v1';
$link = urlencode($url);
$desc = urlencode($description);
$apicall = "https://$dusername:$dpassword@$api/posts/add?&url=$link&description=$desc";
$ch = curl_init($apicall);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, 'php - curl');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($ch);
}
In the real code, $dusername and $dpassword are my actual credentials.
When called from PHP, it fails to add a bookmark. However if I echo $apicall, and go to it directly with FireFox, the bookmark is added. So, this makes me assume there's an error in my cURL implementation. I tried commenting out the lines where it sets CURLOPT_SSL_VERIFYHOST
and CURLOPT_USERAGENT
, but that didn't work either.
This is driving me crazy because at first I rolled my own code, which didn't work. Now I'm using code someone has (allegedly) got working for themselves, and still no luck.
Any help is greatly appreciated, thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在验证证书颁发机构的证书时似乎遇到问题。不确定你如何解决这个问题,但你也许可以像这样回避它:
It seems you have a problem verifying the Certificate Authority's certificate. Not sure how you fix this but you might be able to sidestep it like this: