Twilio 无效的访问令牌 - Swift [英] Twilio Invalid Access Token - Swift

查看:34
本文介绍了Twilio 无效的访问令牌 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循本教程:https://www.youtube.com/watch?v=5lrdYBLEk60 并且收到无效的访问令牌 - 代码:20101 在我按照所有内容进行发球时返回.除了添加带有身份的 Twilio 功能链接之外,我在提供的 VideoQuickStart 中没有任何更改:https://carnelian-chinook-9032.twil.io/video-token?identity=doug

I am attempting to follow this tutorial: https://www.youtube.com/watch?v=5lrdYBLEk60 and am getting Invalid Access Token - Code: 20101 returned when I follow everything to a tee. I changed nothing in the VideoQuickStart provided, other than adding my Twilio function link with identity: https://carnelian-chinook-9032.twil.io/video-token?identity=doug

功能代码(与视频链接相同):

exports.handler = function(context, event, callback) {
    const AccessToken = Twilio.jwt.AccessToken;
    const VideoGrant = AccessToken.VideoGrant;

    const token = new AccessToken(context.ACCOUNT_SID, context.API_KEY, context.API_SECRET);
    token.identity = event.identity;

    const videoGrant = new VideoGrant({
        room: 'TestingRoom'
    });

    token.addGrant(videoGrant);

    callback(null, { token: token.toJwt() });
};

从 VideoQuickStart 示例开始的 ViewController.swift

import UIKit

import TwilioVideo

class ViewController: UIViewController {

    // MARK: View Controller Members

    // Configure access token manually for testing, if desired! Create one manually in the console
    // at https://www.twilio.com/console/video/runtime/testing-tools
    var accessToken = "TWILIO_ACCESS_TOKEN"

    // Configure remote URL to fetch token from
    var tokenUrl = "https://carnelian-chinook-9032.twil.io/video-token?identity=doug"

    // Video SDK components
    var room: TVIRoom?
    var camera: TVICameraSource?
    var localVideoTrack: TVILocalVideoTrack?
    var localAudioTrack: TVILocalAudioTrack?
    var remoteParticipant: TVIRemoteParticipant?
    var remoteView: TVIVideoView?

    // MARK: UI Element Outlets and handles

    // `TVIVideoView` created from a storyboard
    @IBOutlet weak var previewView: TVIVideoView!

    @IBOutlet weak var connectButton: UIButton!
    @IBOutlet weak var disconnectButton: UIButton!
    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet weak var roomTextField: UITextField!
    @IBOutlet weak var roomLine: UIView!
    @IBOutlet weak var roomLabel: UILabel!
    @IBOutlet weak var micButton: UIButton!

    // MARK: UIViewController
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "QuickStart"
....

有人知道我可以为此尝试什么吗?或者,如果他们可以按照教程进行操作并且对他们有效?也许教程有点过时了?也许我需要在我的帐户上启用某些功能?任何帮助,谢谢!

Anyone know what I can try for this? Or if they can follow the tutorial and it works on their end? Maybe the tutorial is a bit outdated? Maybe I need to enable something on my account? Anything helps, thanks!

Repo 例如:https://github.com/twilio/video-quickstart-ios

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

这里的问题是您正在使用测试凭据来创建您的令牌.Twilio 测试凭据 仅用于测试 API 对发送消息请求的响应,购买号码或拨打电话而无需实际触发操作.

The issue here is that you are using Test Credentials to create your token. Twilio test credentials are only useful for testing API responses to requests to send a message, buy a number or make a phone call without actually triggering the action.

切换到您的真实凭据,一切都会正常运行.

Switch out for your real credentials and everything should work just fine.

编辑

使用您链接的快速入门,此代码请求访问令牌,它不解析 JSON 并查找令牌.

Using the quickstart that you linked to, the access token is requested by this code which doesn't parse the JSON and look for the token.

如果您只将令牌作为字符串负载而不是 JSON 负载返回,那么这应该可以工作.要更新函数,请将 callback 更改为:

If you return just the token as a string payload instead of a JSON payload, then this should work. To update the function, change the callback to:

callback(null, token.toJwt()); 

这篇关于Twilio 无效的访问令牌 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆