gpt4 book ai didi

swift - Twilio 无效访问 token - Swift

转载 作者:行者123 更新时间:2023-11-28 13:27:36 32 4
gpt4 key购买 nike

我正在尝试学习本教程:https://www.youtube.com/watch?v=5lrdYBLEk60并收到无效的访问 token - 代码:20101 当我按照所有内容进行操作时返回。除了添加带有标识的我的 Twilio 函数链接外,我在提供的 VideoQuickStart 中没有做任何更改: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() });
};

ViewController.swift 从 VideoQuickStart 示例开始

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"
....

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

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

最佳答案

此处为 Twilio 开发人员布道师。

这里的问题是您正在使用测试凭证来创建您的 token 。 Twilio test credentials仅用于测试 API 对发送消息、购买号码或调用电话的请求的响应,而无需实际触发操作。

切换为您的真实凭据,一切都应该正常工作。

编辑

使用您链接到的快速入门,the access token is requested by this code它不解析 JSON 并查找 token 。

如果您只返回 token 作为字符串有效负载而不是 JSON 有效负载,那么这应该有效。要更新函数,请将 callback 更改为:

callback(null, token.toJwt()); 

关于swift - Twilio 无效访问 token - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107499/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com