Question

I've created a script which retrieves data from Delicious like this:

...retrieve usernames and such...

$username = 'randomUser';
$parentTag = array("tag'12","tag’12"); //note the different quotes being used!
$amount = 100;

foreach ($parentTag as $pTag){
    $url = "http://feeds.delicious.com/v2/json/".$username."/".$pTag."?count=".$amount;     
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);

    ...store data to DB...
}

When manually visiting both links (with the different tags) Delicious displays different data as it treats both as individual/different tags and users have used both types of quotes. When using my script to access the data the first one works but the second one fails and shows no data at all.

I've tried urlencoding and rawurlencoding the tags, manually replacing the curly quote with &#8217 ; and %92 but to no avail.

So the question is: How can I alter my script to get the JSON data of both tags from Delicious?

Was it helpful?

Solution 2

Finally found a solution to the problem which might help others in the future. Not sure if it's the best solution to this problem, but it worked.

Willem-Jan pointed me in the right direction about encoding. I used Firefox's add-on Live HTTP Headers to investigate the way the URL was sent to Delicious. The link "http://feeds.delicious.com/v2/json/username/tag’12?count=100" tranformed into "http://feeds.delicious.com/v2/json/username/tag%E2%80%9912?count=100".

When using the already translated URL as $url variable the request displayed the correct results.

OTHER TIPS

Not a real answer. But for me this just works:

<?php
    // Used sprintf to keep it readable, shouldn't make a difference
    $urlTemplate = 'http://feeds.delicious.com/v2/json/%s/%s?count=%d';
    $tag = 'tag’12';
    $url = sprintf($urlTemplate, 'wjzijderveld', $tag, 20);

    echo $url . PHP_EOL;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    var_dump(json_decode(curl_exec($ch))).PHP_EOL;
    curl_close($ch);

I tried it from the terminal. Only thing I can think of, is that you data might not be utf-8 encoded?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top