1

我正在尝试使用 getstream.io 的客户端功能(特别是提要拉取和实时更新)在使用 react-native 构建的本机应用程序上构建流。当我尝试使用从服务器传递的令牌在 javascript 代码中初始化客户端时,出现错误:

[Error: Missing app id, which is needed to subscribe, use var client = stream.connect(key, secret, appId);]

但是,当我添加秘密和 appId 时(出于测试目的,我会非常警惕这样的部署)我收到错误:

[Error: You are publicly sharing your private key. Dont use the private key while in the browser.]

有没有办法让客户端版本使用 Expo(Create React Native App 默认)运行而不从 Create React Native App 弹出?

4

1 回答 1

2

出于安全原因,您不能使用 JS 客户端生成令牌客户端,因为这需要共享您的 Api Key Secret。

要走的路是让您的后端创建特定于提要的令牌并将它们发送到您的客户端应用程序。

服务器端(红宝石):

require 'stream'
client = Stream::Client.new('YOUR_API_KEY', 'API_KEY_SECRET')
feed = client.feed('user', '1')
token = feed.token

客户端(JS):

client = stream.connect('YOUR_API_KEY', null, 'SITE_ID');
user1 = client.feed('user', '1', token);
于 2017-08-20T18:34:20.937 回答