需要帮助使用 cURL 将书签添加到 Delicious

发布于 2024-08-05 13:35:27 字数 950 浏览 5 评论 0原文

我正在尝试编写一个可以向我的 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_VERIFYHOSTCURLOPT_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 技术交流群。

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

发布评论

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

评论(1

一江春梦 2024-08-12 13:35:27

您在验证证书颁发机构的证书时似乎遇到问题。不确定你如何解决这个问题,但你也许可以像这样回避它:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

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:

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