views:

38

answers:

1

Hi, I've created a javascript bookmarklet that gets the current page's title and URL, using the following code:

//Check to see if jQuery is already loaded
if (typeof jQuery == 'undefined') {
    var jQ = document.createElement('script');
    jQ.type = 'text/javascript';
    jQ.onload=runthis;
    jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
    document.body.appendChild(jQ);
} else {
    runthis();
}

// main Javascript function
function runthis() {
    title = document.title;
    url = document.URL;
    tag = "customTag";

    alert("Added to paperclip: Page Title: "+title+" | URL: "+url);
}

I now want to take that info and add it as a bookmark on my Delicious account. How do I go about this with Javascript/jQuery? I've taken a look at the API documentation but am having trouble getting my head around it (completely new to this, and OAuth makes my head spin), and can't find any full code examples to tinker with.

Would really appreciate any help/examples.

+1  A: 

Edit:

You may want to look at this previous question. - "I want to create a Delicious bookmarklet in Firefox that bookmarks the current page with a predefined tag."


Well, an example that does exactly what you want by using a bookmarklet in your browser's toolbar is the delicious bookmarklet. It gather information from the page, displays the info in a popup, allowing you to edit it, and then stores it to your account:

http://delicious.com/help/bookmarklets

javascript:(function(){
    f= 'http://delicious.com/save?url=' 
    + encodeURIComponent(window.location.href)
    + '&title='+encodeURIComponent(document.title)
    + '&v=5&';
    a=function(){
        if( !window.open(
            f + 'noui=1&jump=doclose',
            'deliciousuiv5',
            'location=yes,
            links=no,scrollbars=no,
            toolbar=no,width=550,height=550'))location.href=f + 'jump=yes'
    };
    if(/Firefox/.test(navigator.userAgent)){
        setTimeout(a,0)
    } else {
      a()
    }
})()

If you use your Yahoo ID to log in, you do have to use OAuth, but if you don't, you can use the V1 api like this (from this page, worked for me in Chrome):

javascript:(

    function()
    {
        location.href = 'https://user:[email protected]/v1/posts/add?url=' 
            + encodeURIComponent(window.location.href)
            + '&description=' + encodeURIComponent(document.title)   
            + '&tags=obvioustesttag';
    }

)()

Make sure to search your tags for "obvioustesttag" since it doesn't show up in the chronological list immediately.

Try to create a regular login or new account if you currently use YahooID to sign in, otherwise, you'll have to deal with OAuth.

Peter Ajtai
Yeah I'm basically wanting to do the same without the popup window and adding in an automatic tag, how would I modify the above to do that?
Chris Armstrong
You'd have to use http://delicious.com/help/api#posts_add . It's a version 1 api, so I don't believe OAuth is necessary. I'm trying to get a working example.
Peter Ajtai
Yeah that's where I'm hitting a wall... I have my OAuth API Key and Secret, but no idea how to actually use it, can't find any practical examples
Chris Armstrong
Thanks, but I think I have to use the OAuth version (v2) because my account is Yahoo-based
Chris Armstrong
Yeah. It looks like it, unless you create a regular login or another account.
Peter Ajtai
Thanks, looks like they don't let you create non-yahoo accounts now, so guess I'll have to get my head around OAuth. Have marked you as answer anyway, thanks for your help. Do you know of any good resources for getting started with the whole OAuth process?
Chris Armstrong
Here's an example from delicious: http://delicious.com/help/oauthapi
Peter Ajtai