使用 Pusher 为我的用户提供实时 API
我正在使用 Pusher 向我的应用程序添加实时功能。有没有办法通过 API 为我的用户提供实时功能?我正在使用私有通道和在线通道,因此需要对这些通道的连接进行身份验证。有没有人与 Pusher 合作并向用户提供某种 API?
我正在使用 Rails 3.1 执行此操作。
I'm using Pusher to add realtime functionality to my app. Is there a way to provide my users with realtime functionality through an API? I'm using private and presence channels, so connections to these need to be authenticated. Has anyone worked with Pusher and provided some sort of API to their users?
I'm doing this using Rails 3.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的解决方案是向您希望能够访问您的数据的用户提供您的
app_key
(不是app_secret
)。然后他们可以连接到 Pusher 并尝试订阅您的频道。他们需要使用JSONP
身份验证,它会调用您的服务器,您可以在其中验证对 private 的请求,或者<一href="http://pusher.com/docs/presence" rel="nofollow">状态频道。在身份验证中,您需要检查引荐来源网址(域),看看您是否授予他们访问您的数据以及他们订阅的内容的权限。
您还可以将此 JavaScript 封装在您自己的库中,以便
subscription_error
(身份验证错误)断开客户端与 Pusher 的连接。希望这有帮助。您也可以随时发送电子邮件至[电子邮件受保护]。
The solution here is to give the users you want to be able to access your data your
app_key
(notapp_secret
). They can then connect to Pusher and try to subscribe to your channels. They'll need to useJSONP
authentication which makes a call to your server where you can authenticate the request to the private or presence channels.In your authentication you'll need to check the referrer (domain) to see if you've given them access to your data along with what they are subscribing to.
You could also wrap this JavaScript up in your own library so that a
subscription_error
(authentication error) disconnects the client from Pusher.Hope this helps. You can always drop an email to [email protected] too.