修改Twitter Opera Widget的API地址
July 30th, 2009 | by vvoody |看到@yegle兄把TwitterFox的API改成了第三方的twitter api proxy,想到Opera的那个Twitter Widget估计也可以改。
找到Twitter Opera Widget的wgt文件,发现它其实就是个zip,解压后把所有文件浏览了遍,基本确定是要对script/twitter-api.js这个文件动手。它原来是直接调用Twitter官方的API,现在我通通把http[s]://twitter.com的地方改成第三方API,比如http://nest.onedd.net/api。嗯,应该是这样。
可是,它竟然提示”Could not contact Twitter.”。我没想通为啥不行,直接调用nest.onedd.net的API是可以的。后来google、抓包都没啥结果。源代码也没看出啥不对劲的。然后跑到论坛的Widget,发现竟然已有前人做了此事[1],主要方法就是上面说的。不过,关键得在config.xml里加一句“nest.onedd.net”。OMG,终于可以了!
host标签是限定widget可访问的主机名。文档[2]中明确注明了这点,可我懒得去翻,结果就是为了这个弄了一个上午 =.=!! 不看文档的下场。。。
我对原来的Twitter Opera widget_7206_3.22.wgt做了修改,重新打包,想直接用的朋友点这里下载。
下面贴个diff就能明白对原来的Twitter Opera Widget做了些啥:
diff -u -r Twitter Opera widget_7206_3.22/config.xml Twitter Opera widget_7206_3.22-nest.onedd.net/config.xml --- Twitter Opera widget_7206_3.22/config.xml 2009-06-05 11:00:34.000000000 +0800 +++ Twitter Opera widget_7206_3.22-nest.onedd.net/config.xml 2009-07-30 10:46:22.000000000 +0800 @@ -17,9 +17,10 @@ <protocol>http</protocol> <host>api.twitter.com</host> <host>twitter.com</host> + <host>nest.onedd.net</host> <host>maps.google.com</host> <host>widgets.opera.com</host> <host>search.twitter.com</host> </access> </security> -</widget> \ No newline at end of file +</widget> diff -u -r Twitter Opera widget_7206_3.22/script/twitter-api.js Twitter Opera widget_7206_3.22-nest.onedd.net/script/twitter-api.js --- Twitter Opera widget_7206_3.22/script/twitter-api.js 2009-06-05 11:00:34.000000000 +0800 +++ Twitter Opera widget_7206_3.22-nest.onedd.net/script/twitter-api.js 2009-07-30 10:46:50.000000000 +0800 @@ -57,7 +57,7 @@ publicTimeline: function(callback, errorCallback) { makeRequest({ method: 'GET', - url: 'http://twitter.com/statuses/public_timeline' + format, + url: 'http://nest.onedd.net/api/statuses/public_timeline' + format, callback: callback, errorCallback: errorCallback }, true); @@ -69,7 +69,7 @@ makeRequest({ method: 'GET', - url: 'https://twitter.com/statuses/friends_timeline' + format + query, + url: 'http://nest.onedd.net/api/statuses/friends_timeline' + format + query, headers: { 'Cache-Control': 'no-cache' }, @@ -86,7 +86,7 @@ makeRequest({ method: 'GET', - url: 'https://twitter.com/statuses/user_timeline' + format + query, + url: 'http://nest.onedd.net/api/statuses/user_timeline' + format + query, headers: { 'Cache-Control': 'no-cache' }, @@ -101,7 +101,7 @@ show: function(id, callback, errorCallback) { makeRequest({ method: 'GET', - url: 'https://twitter.com/statuses/show/' + id + format, + url: 'http://nest.onedd.net/api/statuses/show/' + id + format, username: this.username, password: this.password, callback: callback, @@ -115,7 +115,7 @@ makeRequest({ method: 'POST', - url: 'https://twitter.com/statuses/update' + format + query, + url: 'http://nest.onedd.net/api/statuses/update' + format + query, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -134,7 +134,7 @@ makeRequest({ method: 'GET', - url: 'https://twitter.com/statuses/mentions' + format + query, + url: 'http://nest.onedd.net/api/statuses/mentions' + format + query, username: this.username, password: this.password, callback: callback, @@ -146,7 +146,7 @@ destroy: function(id, callback, errorCallback) { makeRequest({ method: 'DELETE', - url: 'https://twitter.com/statuses/destroy/' + id + format, + url: 'http://nest.onedd.net/api/statuses/destroy/' + id + format, username: this.username, password: this.password, callback: callback, @@ -160,7 +160,7 @@ friends: function(callback, errorCallback) { makeRequest({ method: 'GET', - url: 'https://twitter.com/statuses/followers' + format, + url: 'http://nest.onedd.net/api/statuses/followers' + format, username: this.username, password: this.password, callback: callback, @@ -174,7 +174,7 @@ directTimeline: function(callback, errorCallback) { makeRequest({ method: 'GET', - url: 'https://twitter.com/direct_messages' + format, + url: 'http://nest.onedd.net/api/direct_messages' + format, username: this.username, password: this.password, callback: callback, @@ -188,7 +188,7 @@ verifyCredentials: function(username, password, callback, errorCallback) { makeRequest({ method: 'HEAD', - url: 'https://twitter.com/account/verify_credentials' + format, + url: 'http://nest.onedd.net/api/account/verify_credentials' + format, username: username, password: password, callback: callback, @@ -200,7 +200,7 @@ endSession: function(callback) { makeRequest({ method: 'POST', - url: 'http://twitter.com/account/end_session', + url: 'http://nest.onedd.net/api/account/end_session', callback: callback, errorCallback: callback }); @@ -212,7 +212,7 @@ createFriendship: function(id, callback, errorCallback) { makeRequest({ method: 'POST', - url: 'https://twitter.com/friendships/create/' + id + format, + url: 'http://nest.onedd.net/api/friendships/create/' + id + format, username: this.username, password: this.password, callback: callback, @@ -224,7 +224,7 @@ destroyFriendship: function(id, callback, errorCallback) { makeRequest({ method: 'DELETE', - url: 'https://twitter.com/friendships/destroy/' + id + format, + url: 'http://nest.onedd.net/api/friendships/destroy/' + id + format, username: this.username, password: this.password, callback: callback, @@ -236,7 +236,7 @@ friendshipExists: function(id, callback, errorCallback) { makeRequest({ method: 'POST', - url: 'https://twitter.com/friendships/exists/' + id + format, + url: 'http://nest.onedd.net/api/friendships/exists/' + id + format, username: this.username, password: this.password, callback: callback,
[1] Opera Twitter Widget 复活手记 – http://bbs.operachina.com/viewtopic.php?f=38&t=49093
[2] Opera Widget 规范 1.0 第三版 – http://kb.operachina.com/node/98#xml_security
5 Responses to “修改Twitter Opera Widget的API地址”
By baozi on Jan 29, 2010
Opera 9.80 Windows XP Opera 9.80 Windows XP不能下载了.check
Reply
vvoody Reply:
Opera 9.80 Windows XPJanuary 29th, 2010 at 23:46
奇怪,那个目录整个没了。。。。 现在可以了
Reply
baozi Reply:
Opera 9.80 Windows XPJanuary 30th, 2010 at 12:35
ok,谢谢.好像改动了很多地方呀
Reply
vvoody Reply:
Opera 9.80 LinuxJanuary 30th, 2010 at 13:34
是吗,只改了api~