我正在尝试遵循本教程:https://www.youtube.com/watch?v=5lrdYBLEk60,并且在我将所有内容放在发球台上时都收到无效访问令牌-代码:20101。除了添加标识为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"
....
有人知道我可以为此做些什么吗?或者,如果他们可以按照本教程进行操作,并且最终可以正常工作?也许教程有点过时了?也许我需要在我的帐户上启用某些功能?有什么帮助,谢谢!
答案 0 :(得分:1)
这里是Twilio开发人员的传播者。
此处的问题是您正在使用测试凭据来创建令牌。 Twilio test credentials仅在测试API对请求发送消息,购买号码或打电话而没有实际触发操作的响应时有用。
切换出您的真实凭据,一切都会正常进行。
修改
使用您链接的快速入门the access token is requested by this code,它不会解析JSON并查找令牌。
如果仅将令牌作为字符串有效负载而不是JSON有效负载返回,那么这应该可以工作。要更新功能,请将callback
更改为:
callback(null, token.toJwt());