问题
I am trying to use Twilio Video for which I need to obtain access tokens(jwt) from my app server.
Below is the NodeJS app server code that generates an Access token. In the below credentials, API_KEY_SECRET is required, I thought this is same as Twilio Auth token that can be found in the Twilio console.
Is my understanding correct ? if not, where can I find the API_KEY_SECRET ?
var AccessToken = require('twilio').AccessToken;
// Substitute your Twilio AccountSid and ApiKey details
var ACCOUNT_SID = 'accountSid';
var API_KEY_SID = 'apiKeySid';
var API_KEY_SECRET = 'apiKeySecret';
// Create an Access Token
var accessToken = new AccessToken(
ACCOUNT_SID,
API_KEY_SID,
API_KEY_SECRET
);
// Set the Identity of this token
accessToken.identity = 'example-user';
// Grant access to Conversations
var grant = new AccessToken.ConversationsGrant();
grant.configurationProfileSid = 'configurationProfileSid';
accessToken.addGrant(grant);
// Serialize the token as a JWT
var jwt = accessToken.toJwt();
console.log(jwt);
回答1:
When you create API Key(API_KEY_SID) - you'll be shown the Key's secret(API_KEY_SECRET),
You'll use the the secret(API_KEY_SECRET) of the API Key(API_KEY_SID) you created in step 1 to generate an access-token(ACCESS_TOKEN) using the Twilio Helper Library
Detailed Explanation here - Twilio Authorization - Refer the step 1,2,3, Its explained with example in different languages, including Nodejs.
回答2:
Set<Integer> board = new HashSet<Integer>();
for(int i = 0; i < scores.length; i++){
board.add(Integer.valueOf(scores[i]));
}
List<Integer> finalBoard = new ArrayList<Integer>(board);
Collections.sort(finalBoard);
int[] aliceRank = new int[alice.length];
int aliceScore;
int boardNo = 0;
for(int i = 0; i < alice.length; i++){
aliceScore = alice[i];
for(int j = boardNo; j < finalBoard.size(); j++){
if(aliceScore > finalBoard.get(boardNo)){
continue;
} else if(aliceScore <= finalBoard.get(j)){
aliceRank[i] = finalBoard.size() -
}
}
}
// Step 1 - Ranking the Scores to leader board
Arrays.sort(scores);
int[] rankBoard = new int[scores.length];
for(int i = scores.length - 1; i >= 0; i--){
rankBoard[scores.length - i - 1] = scores[i];
}
//Step 2 - Removing the duplicates
Set<Integer> cleanBoard = new HashSet<Integer>();
for
return output;
}
来源:https://stackoverflow.com/questions/41754225/is-twilio-api-key-secret-is-same-as-the-twilio-auth-token-in-console