gpt4 book ai didi

go - 从Golang的Twilio获取访问 token

转载 作者:行者123 更新时间:2023-12-01 21:09:22 28 4
gpt4 key购买 nike

我将Golang用于后端,我需要从Twilio获取访问 token ,但找不到适用于Golang的任何库。
NodeJS中的示例代码为:

const AccessToken = require('twilio').jwt.AccessToken;
const VideoGrant = AccessToken.VideoGrant;

// Used when generating any kind of Access Token
const twilioAccountSid = 'ACxxxxxxxxxx';
const twilioApiKey = 'SKxxxxxxxxxx';
const twilioApiSecret = 'xxxxxxxxxxxx';

// Create an access token which we will sign and return to the client,
// containing the grant we just created
const token = new AccessToken(twilioAccountSid, twilioApiKey, twilioApiSecret);
token.identity = 'alice';

// Create a Video grant which enables a client to use Video
// and limits access to the specified Room (DailyStandup)
const videoGrant = new VideoGrant({
room: 'DailyStandup'
});

// Add the grant to the token
token.addGrant(videoGrant);

// Serialize the token to a JWT string
console.log(token.toJwt());
我尝试了这个库-> https://github.com/xaviiic/twilioGo,但是没有运气。

最佳答案

使用链接的库(https://github.com/xaviiic/twilioGo),代码/方法等与NodeJS样本代码非常接近:

import twilio "github.com/xaviiic/twilioGo"

var (
accountID = "AC...."
keyID = "SK...."
secret = "....."
)

token := twilio.NewAccessToken(accountID, keyID, secret)
identity := "alice"
token.SetIdentity(identity)

videoGrant := twilio.NewVideoGrant("DailyStandup")
token.AddGrant(videoGrant)

log.Println(token.ToJWT())
https://play.golang.org/p/6mEpQqisITf
注意:虽然以上将在 GOPATH环境中构建(即使用最新的项目提交),但在进行 go modules构建时需要一些帮助:
# this will initially fail:
go build

# choose latest commit of this dependency - latest v0.9.1 tag appears to be incompatible
go get github.com/SermoDigital/jose@master

go build

关于go - 从Golang的Twilio获取访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63863665/

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