菜鸟教程小白 发表于 2022-12-11 16:49:38

ios - Twilio 视频 + 解析


                                            <p><p>我正在使用 Twilio-Video (<a href="https://www.twilio.com/docs/api/video" rel="noreferrer noopener nofollow">https://www.twilio.com/docs/api/video</a>) 构建应用程序。我用解析做了用户管理数据库,但访问 token 有问题。 </p>

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

<p> <a href="https://www.twilio.com/docs/api/video/guide/identity" rel="noreferrer noopener nofollow">https://www.twilio.com/docs/api/video/guide/identity</a> </p>

<p>谢谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这里是 Twilio 开发者宣传员。</p>

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

<p>您实际上并不想为 <a href="https://www.twilio.com/docs/api/video" rel="noreferrer noopener nofollow">Twilio Video</a> 创建访问 token 当用户注册您的应用程序时。 token 是可配置的,可以持续长达 24 小时。因此,您希望在用户需要时生成 token 。</p>

<p>解析服务器是一个基于 Node.js 的服务器和 <a href="https://www.npmjs.com/package/parse-server#parse-server--express" rel="noreferrer noopener nofollow">can be embedded within an Express server</a> .一旦你这样做了,你就可以安装最新的 <a href="https://www.npmjs.com/package/twilio" rel="noreferrer noopener nofollow">Twilio npm module</a>并使用它从 Express 端点为您的用户生成 token 。</p>

<p>生成 token 所需的代码如下所示:</p>

<pre><code>var AccessToken = require(&#39;twilio&#39;).AccessToken;
var IpMessagingGrant = AccessToken.IpMessagingGrant;

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

// Used specifically for creating IP Messaging tokens
var serviceSid = &#39;ISxxxxxxxxxxxxx&#39;;
var appName = &#39;HipFlowSlackDockRC&#39;;
var identity = &#39;[email protected]&#39;;
var deviceId = &#39;someiosdeviceid&#39;;
var endpointId = appName + &#39;:&#39; + identity + &#39;:&#39; + deviceId;

// Create a &#34;grant&#34; 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.
</code></pre>

<p>欲了解更多信息,请查看 <a href="https://www.twilio.com/docs/api/rest/access-tokens#creating-tokens" rel="noreferrer noopener nofollow">Twilio API reference for creating access tokens</a> .</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Twilio 视频 &#43; 解析,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/38022683/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/38022683/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Twilio 视频 &#43; 解析