Google Api Feed - 多请求
是否可以同时请求 1 个以上的 Feed?
例如
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'1\'),get_it(\'http://rss.golem.de/rss.php?feed=RSS1.0\',\'99\')'});
或...
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'99\')'});
google.load("feeds", "1",{"callback" : 'get_it(\'http://rss.golem.de/
rss.php?feed=RSS1.0\',\'99\')'});
两种解决方案都有效,但我不确定,这是正确的吗 (干净)方式?
提前致谢! 彼得
is it possible to request more than 1 Feed at the same time?
for example
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'1\'),get_it(\'http://rss.golem.de/rss.php?feed=RSS1.0\',\'99\')'});
or ...
google.load("feeds", "1",{"callback" : 'get_it(\'http://
www.fernsehkritik.tv/?feed=podcast\',\'99\')'});
google.load("feeds", "1",{"callback" : 'get_it(\'http://rss.golem.de/
rss.php?feed=RSS1.0\',\'99\')'});
Both solutions are working but i am not sure, is this the right
(clean) way?
Thanks in advance!
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我认为你对正在发生的事情有点困惑。当您调用
google.load("feeds", "1",{"callback": "get_it('http://myfeed.com/whatever')"})
时,您不是请求 Google 加载http://myfeed.com/whatever
上的 Feed。你的意思是:“嘿,Google,加载 javascript 以支持您的 feed api,当您的 feed api 全部加载并准备好使用时,调用get_it('http://myfeed.com/无论如何')
,其中大概get_it
是您已经在页面中定义的函数,它使用 Google 的 feed api 来完成其任务,所以我认为通过定义可以更好地实现您的目的 。一个 javascript 函数来执行 feed 已准备好,类似于:
然后简单地调用:
当 Google API 全部加载时,这将立即执行两个“go get the feeds”函数
现在,至于获取 feed 。并行:无论您相信与否,Javascript 也不会真正具有任何阻止和等待网络 I/O 的能力,因此 JavaScript 中从网络获取内容的任何内容都必须编写。形式:“发出这个网络请求,当您最终得到响应时,将调用一个函数”,但与此同时,浏览器上的 JavaScript 引擎会继续运行,而不等待响应返回。
这意味着,在上面,您将触发对
http://www.fernsehkritik.tv/?feed=podcast
的请求,并且您的浏览器将继续执行 JavaScript,而无需等待网络响应,并且您将触发http://rss.golem.de/rss.php?feed=RSS1.0
的第二个请求。因此,即使浏览器中的 javascript 不允许执行多线程,两个提要的网络流量也会并行返回到您的浏览器。So I think you're a slight bit confused at to what's going on. When you call
google.load("feeds", "1",{"callback": "get_it('http://myfeed.com/whatever')"})
, you're not requesting that Google go load the feed athttp://myfeed.com/whatever
. What you're saying is: "Hey, Google, load up the javascript to support your feed api, and when your feed api is all loaded and ready to use, callget_it('http://myfeed.com/whatever')
, where presumablyget_it
is a function you've defined already in your page that uses Google's feed api to do its thing.So I think your purpose would be better served by defining a single javascript function to execute one the feed is ready, something like:
And then calling simply:
That'll execute both "go get the feeds" functions right away when the Google API is all loaded.
Now, as for getting the feeds in parallel: believe it or not, that will also load the feeds in parallel. Javascript doesn't really have any ability to block and wait on network I/O, so anything in javascript that gets stuff from the network always has to be written in the form: "Go make this network request, and here's a function to call when you eventually get a response". But in the meantime, the javascript engine on the browser keeps going without waiting for the response to come back.
This means that above, you'll fire off the request for
http://www.fernsehkritik.tv/?feed=podcast
and your browser will continue executing javascript without waiting for the network to respond, and you'll fire off the second request forhttp://rss.golem.de/rss.php?feed=RSS1.0
. So the network traffic for both feeds will then be coming back to your browser in parallel, even though javascript in the browser doesn't allow multiple threads of execution.