2010-07-19 70 views
2

我創建了一個JavaScript書籤獲取當前網頁的標題和URL,使用下面的代碼:創建「發送到Delicious」書籤與自定義標籤

//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); 
} 

我現在想利用這些信息和將其添加爲我的Delicious帳戶上的書籤。我怎麼用Javascript/jQuery去解決這個問題?我看了一下API documentation,但是我很難找到它(這是全新的,而且OAuth讓我頭暈目眩),並且找不到任何完整的代碼示例來修補。

真的很感謝任何幫助/例子。

回答

1

編輯:

You may want to look at this previous question. - 「我想創造在Firefox美味書籤與預定義的標記爲書籤當前頁面。」


嗯,這不正是你想要通過使用瀏覽器的工具欄上的一個書籤什麼好吃的書籤的例子。它從頁面收集信息,顯示在一個彈出窗口中的信息,讓您編輯它,然後將其保存到您的帳戶:

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() 
    } 
})() 

如果您使用雅虎ID來登錄後,你必須使用OAuth,但如果你不這樣做,你可以使用1.0版API這樣的(從this page,在Chrome工作對我來說):

javascript:(

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

)() 

確保搜索您的標籤「明顯的標籤」,因爲它不會立即顯示在時間順序列表中。

如果您當前使用YahooID登錄,請嘗試創建常規登錄帳戶或新帳戶,否則,您必須處理OAuth。

+0

是的,我基本上想要做同樣的事情,沒有彈出窗口,並添加一個自動標記,我將如何修改上述做到這一點? – 2010-07-19 20:28:25

+1

您必須使用http://delicious.com/help/api#posts_add。這是一個版本1 API,所以我不相信OAuth是必要的。我試圖得到一個工作的例子。 – 2010-07-19 20:47:22

+0

是的,這就是我打牆的地方......我有我的OAuth API密鑰和祕密,但不知道如何實際使用它,找不到任何實際示例 – 2010-07-19 20:50:32