使用Delicious API在Firefox中创建Delicious小书签 [英] Create a Delicious Bookmarklet in Firefox using Delicious API

查看:177
本文介绍了使用Delicious API在Firefox中创建Delicious小书签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



为了证明概念,如果我输入这个URL,它可以工作:

  https:// john:pwd@api.del.icio.us/v1/posts/add?url = http ://www.google.com& 
description = http://www.google.com& tags = testtag

作为一个小书签没有,我得到访问被拒绝

  javascript :( 

function()
{
location.href ='https:// john:pwd@api.del.icio.us/v1/posts/add?url ='
+ encodeURIComponent(window.location.href)
+& description ='+ encodeURIComponent(document.title)
+& tags = testtag';
}

)()

可以通过javascript书签吗?



更新:我试过这个,但仍然得到了访问被拒绝的错误,所以它与Javascript / Firefox有关。 >

  javascript :( 

函数()
{
location.href ='https :// john:pwd@api.del.icio.us/v1/posts/add?url ='
+'http://www.google.com'
+'& d escription ='+'http://www.google.com'+'& tags = testtag';

$ b)()

更新2 :
在尝试了以上和不同浏览器的许多变体后,我仍然无法越过访问被拒绝的消息,因此提供了赏金。

解决方案

我怀疑这是Firefox在运行Javascript时试图保护您免于安全问题。当我尝试在地址栏输入你的例子时,Firefox提示我询问是否确定要登录到 api.del.icio.us 。 p>

有关 HTTP auth 看起来类似于你的问题,也许它会帮助你。




更新:我使用了Firebug的 Net 面板和它的Javascript控制台,并且能够看到请求/响应标题。



以下是来自Javascript控制台的请求:失败:

  GET / v1 /posts/add?url=http://www.spoons.com/&description=forks&tags=knives HTTP / 1.1 
主机:api.del.icio.us
用户代理: Mozilla / 5.0(Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3)Gecko / 20100401 Firefox / 3.6.3
接受:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8
Accept-Language:en-us,en; q = 0.5
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7
Keep-Alive:115
连接:keep -alive
Referer:https://stackoverflow.com/questions/2708950/2740195
授权:基本XXXXXXXXXXXXXXXXX
Cache-Control:max-age = 0

$ p
$ b $ p



$ p> GET /v1/posts/add?url=http://www.spoons.com/&description=forks&tags=knives HTTP / 1.1
主机:api.del .icio.us
用户代理:Mozilla / 5.0(Windows; U; Windows NT 5.1; EN-US; rv:1.9.2.3)Gecko / 20100401 Firefox / 3.6.3
接受:text / html,application / xhtml + xml,application / xml; q = 0.9,* / *; q = 0.8
接受-Language:en-us,en; q = 0.5
Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7
Keep-Alive:115
连接:保持活动
授权:基本XXXXXXXXXXXXXXXXX
Cache-Control:max-age = 0

唯一的区别似乎是 Referer 标题,导致访问被拒绝响应。 Firefox的 about.config 中的设置 network.http.sendRefererHeader 可以设置为0,这会关闭 Referer 标题。当我尝试这个,然后Javascript控制台方法开始工作。

有一个名为 refspoof < a>,这对发送自定义的 Referer 标题非常有用,也许可以在这里帮助。


I want to create a Delicious bookmarklet in Firefox that bookmarks the current page with a predefined tag.

For proof of concept, if I enter this url, it works:

https://john:pwd@api.del.icio.us/v1/posts/add?url=http://www.google.com&
    description=http://www.google.com&tags=testtag

But this as a bookmarklet doesn't, I get access denied:

javascript:(

    function()
    {
        location.href = 'https://john:pwd@api.del.icio.us/v1/posts/add?url=' 
            + encodeURIComponent(window.location.href)
            + '&description=' + encodeURIComponent(document.title)   
            + '&tags=testtag';
    }

)()

Is this possible via a javascript bookmark?

Update: I tried this, but still got the access denied error, so it has something to do with Javascript/Firefox.

javascript:(

    function()
    {
        location.href = 'https://john:pwd@api.del.icio.us/v1/posts/add?url='
            + 'http://www.google.com'
            + '&description=' + 'http://www.google.com' + '&tags=testtag';
    }

)()

Update 2: After trying many variations of the above and on different browsers, I still can't get past the access denied message, so offering a bounty.

解决方案

I suspect this is Firefox trying to protect you from security issues when running Javascript. When I tried typing in your example into my address bar, Firefox prompted me to ask if I am sure I want to log in to api.del.icio.us.

This other question concerning HTTP auth looks similar to your question, maybe it will help you.


Update:

I used Firebug's Net panel and its Javascript console, and I was able to see the request/response headers.

Here is the request from the Javascript console, which FAILED:

GET /v1/posts/add?url=http://www.spoons.com/&description=forks&tags=knives HTTP/1.1
Host: api.del.icio.us
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: https://stackoverflow.com/questions/2708950/2740195
Authorization: Basic XXXXXXXXXXXXXXXXX
Cache-Control: max-age=0

And, here is the request from the address bar, which WORKED:

GET /v1/posts/add?url=http://www.spoons.com/&description=forks&tags=knives HTTP/1.1
Host: api.del.icio.us
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Authorization: Basic XXXXXXXXXXXXXXXXX
Cache-Control: max-age=0

The only difference seems to be the Referer header, which caused the access denied response. The setting network.http.sendRefererHeader in Firefox's about.config can be set to 0 which turns off the Referer header. When I tried this, then the Javascript console method started working.

There is a Firefox extension called refspoof which is useful for sending your own custom Referer headers, maybe that can help here.

这篇关于使用Delicious API在Firefox中创建Delicious小书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆