The del.icio.us API authentication is not cookie-based, but rather is  
HTTP authentication based:

http://del.icio.us/help/api/

So, with curl in PHP, you want to use:

curl_setopt($ch, CURLOPT_USERPWD, "dummy007:gopal123");

on each request to provide the authentication info each time. An HTTP  
401 is either an initial challenge or a subsequent failed login over  
HTTP authentication.

You shouldn't have to worry about the cookie at all.

JM

On Mar 28, 2007, at 1:33 AM, gopalrulz wrote:

> Since accessing del.icio.us API services require Authentication ,i
> tried writing a PHP script which uses curl.The script does a login to
> del.icio.us(https://secure.del.icio.us/login) and then stores the
> authentication cookie in a file and then use the same cookie data to
> access the service (https://api.del.icio.us/v1/posts/update)
>
> But unfortunately i get a HTTP 401 - Not Authorised Error even though
> am passing the cookie.
>
> I have also pasted the PHP code .Kindly let me know where am going  
> wrong.
>
> <?php
> define("OK", 0);
>
> function do_curl($method, $url, $fields)
> {
> $retval = array('error_code' => 0, 'error_string' =>
> 'OK');
> $cookiejar = "/tmp/cookiejar";
>
> $ch = curl_init();
>
> if($method == "POST")
> {
> curl_setopt($ch, CURLOPT_POST, TRUE);
> curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
> }
>
> curl_setopt($ch, CURLOPT_URL, $url );
> curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiejar);
> curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiejar);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
>
> $result = curl_exec($ch);
>
> $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
>
> $retval['result'] = $result;
> $retval['http_code'] = $http_code;
>
> curl_close($ch);
>
> return $retval;
> }
>
> function getupdate()
> {
> $url = "https://api.del.icio.us/v1/posts/update";;
> $result = do_curl("GET", $url, array());
>
> if($result['error_code'] != OK)
> return $result;
>
> if($result['http_code'] != 200)
> {
> $retval = array();
> $retval['error_code'] = "Error";
> $retval['error_string'] = "HTTP Code : " .
> $result['http_code'];
> return $retval;
> }
>
> return $result;
> }
>
> $fields['user_name'] = "dummy007";
> $fields['password'] = "gopal123";
> $url = "https://secure.del.icio.us/login";;;
> $retval = do_curl("POST", $url, $fields);
>
> print_r($retval);
> print_r(getupdate());
> ?>
>
> Thanks,
> Gopal
>
>
> 

-- 
Justin R. Miller
Code Sorcery Workshop
http://codesorcery.net


Reply via email to