如何使用 OpenSocial 访问 access gadgets.*
如果我的内容类型是 URL,是否可以在 JavaScript 代码中使用 gadgets.*
?
Is there a way to use gadgets.*
in my JavaScript code if my content type is URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用代理内容功能。这样您就可以从您自己的服务器获取的内容访问 gadgets.* API。
You could use the Proxied Content feature. That way you can access gadgets.* APIs from the content fetched from your own server.
根据 OpenSocial 规范(至少从 0.8 及更高版本开始),请求功能的 JavaScript 库的相对路径链接应在内容 URL 参数中传递。在 OpenSocial 规范中搜索关键字“libs”以获取更多信息。
问题仍然是 URL 中给出的路径是相对路径,而不是绝对路径,您需要知道在何处附加此参数的基本 URL。 此处的讨论主题建议使用基本网址“https://www-gm-opensocial.googleusercontent.com/gadgets/js/”并按原样附加“libs”的值,但我尚未成功验证这一点。我们用来在 iGoogle 上获取 OpenSocial 小工具的库(支持 jQuery)的代码是:
但请注意,并非所有 API 都可以通过这种方式使用,例如 gadgets.io.* 无法通过这种方式启用,其他的还需要测试。
According to the OpenSocial specification (at least starting from 0.8 and later), the relative path link to JavaScript libraries of requested features should be passed in the content URL parameter. Search the OpenSocial specification for keyword 'libs' to get more information.
The problem still is that the path given in URL is relative, not absolute, and you would need to know the base URL where to append this parameter. The discussion thread here suggests to use a base URL "https://www-gm-opensocial.googleusercontent.com/gadgets/js/" and append the value of 'libs' as it is, but I've not successfully verified that. Code that we've used to fetch libraries for the OpenSocial gadget on iGoogle (with jQuery support) is:
NOTE, though, that not all APIs will be available this way, e.g., gadgets.io.* can't be enabled this way, others needs to be tested.