Twilio Invalid Access Token - Swift

旧时模样 提交于 2019-12-25 01:22:28

问题


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

Code for function (same as video linked):

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() });
};

Beginning of ViewController.swift from VideoQuickStart example

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 used for example: https://github.com/twilio/video-quickstart-ios


回答1:


Twilio developer evangelist here.

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.

Edit

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.

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()); 


来源:https://stackoverflow.com/questions/58107499/twilio-invalid-access-token-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!