【问题标题】:Twilio Video + ParseTwilio 视频 + 解析
【发布时间】:2016-10-27 14:54:51
【问题描述】:

我正在使用 Twilio-Video (https://www.twilio.com/docs/api/video) 构建应用程序。我用解析做了用户管理数据库,但访问令牌有问题。

当我的用户在我的应用程序中注册时,我想将 twilio 访问令牌分配给他们的用户名 - 问题是我该怎么做?还是无法解析?我的应用需要额外的后端服务器吗?我有点困惑。

https://www.twilio.com/docs/api/video/guide/identity

谢谢!

【问题讨论】:

  • 这里绝对需要 Parse,你知道it's shutting down 对吗?我可以帮忙,我只需要知道你在哪里。
  • 我知道,我在 heroku 上部署了 parse。如果我想测试我的应用程序,我必须使用 twillio 测试工具生成访问令牌。我不明白的是,我如何使用 Parse-Database 构建 - 为我的用户轻松注册 - 用户名、密码、位置并为其分配访问令牌。 - 因为没有它他们可以与 twilio 通信。我不知道如何在用户注册时为他们生成令牌。 @philnash

标签: ios swift twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

正如您所提到的,您在 Heroku 上使用 Parse 服务器,我相信我可以提供帮助!

当用户注册您的应用程序时,您实际上并不想为Twilio Video 创建访问令牌。令牌是可配置的,可以持续长达 24 小时。因此,您希望在用户需要时生成令牌。

解析服务器是一个基于 Node.js 的服务器和can be embedded within an Express server。完成此操作后,您可以安装最新的 Twilio npm module 并使用它从 Express 端点为您的用户生成令牌。

生成令牌所需的代码如下所示:

var AccessToken = require('twilio').AccessToken;
var IpMessagingGrant = AccessToken.IpMessagingGrant;

// Used when generating any kind of tokens
var twilioAccountSid = 'ACxxxxxxxxxx';
var twilioApiKey = 'SKxxxxxxxxxx';
var twilioApiSecret = 'xxxxxxxxxxxx';

// Used specifically for creating IP Messaging tokens
var serviceSid = 'ISxxxxxxxxxxxxx';
var appName = 'HipFlowSlackDockRC';
var identity = 'user@example.com';
var deviceId = 'someiosdeviceid';
var endpointId = appName + ':' + identity + ':' + deviceId;

// Create a "grant" which enables a client to use IPM as a given user,
// on a given device
var ipmGrant = new IpMessagingGrant({
    serviceSid: serviceSid,
    endpointId: endpointId
});

// Create an access token which we will sign and return to the client,
// containing the grant we just created
var token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.addGrant(ipmGrant);
token.identity = identity;

// Serialize the token to a JWT string
console.log(token.toJwt());
// For your app you want to return the token to the front end somehow.

如需了解更多信息,请查看Twilio API reference for creating access tokens

【讨论】:

  • 感谢您的回答。我在 Heroku 上部署了 Parse Server (github.com/ParsePlatform/parse-server-example)。我的应用程序已经完成,但我仍然不明白我现在如何使用这个 Twilio npm 模块从 parse 生成令牌?你能再解释一下吗?
  • 好的,到目前为止,您为尝试生成令牌做了什么?您是否尝试过使用我回答中的代码?
  • 对不起,我的反应迟了,我正在度假。所以我的第一个问题 - 我可以使用 Twilio 试用帐户生成令牌还是必须先升级我的帐户?我问是因为我找不到这些信息 - twilioAccountSid、twilioApiKey、twilioApiSecret。我使用此链接 github.com/ParsePlatform/parse-server-example 部署了 Parse。下一步我该怎么做?很抱歉提出这些愚蠢的问题,但我还是新手。
  • 没问题!您可以在Twilio console 的帐户摘要下找到您的帐户 SID。您可以在dev tools section 中创建 API Key 和 API Secret。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-09
相关资源
最近更新 更多