使用PHP不工作的Twilio AccessToken
问题描述:
我试图在PHP中使用Swift iPhone应用程序生成服务器端Twilio可编程语音访问令牌,但在注册应用程序中的推送通知时出现太短并失败。使用PHP不工作的Twilio AccessToken
错误是“在注册过程中从服务通知例外未经授权回答:TNException:无法创建注册”
我可以从快速启动使Python中的令牌OK的代码
@app.route('/accessToken', methods=['GET', 'POST'])
def token():
account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
api_key = os.environ.get("API_KEY", API_KEY)
api_key_secret = os.environ.get("API_KEY_SECRET", API_KEY_SECRET)
push_credential_sid = os.environ.get("PUSH_CREDENTIAL_SID", PUSH_CREDENTIAL_SID)
app_sid = os.environ.get("APP_SID", APP_SID)
grant = VoiceGrant(
push_credential_sid=push_credential_sid,
outgoing_application_sid=app_sid
)
token = AccessToken(account_sid, api_key, api_key_secret,IDENTITY)
token.add_grant(grant)
return str(token)
但是,在转换为PHP时出现了问题 - 这段代码不会引发错误并生成一个令牌,但它的长度为550个字符,而不是570个,正如我所说的,使用时无法注册。
变量都是一样的,我检查他们都在那里。
$token = new AccessToken(
$twilioAccountSid,
$twilioApiKey,
$twilioApiSecret,
3000,
$identity
);
// Create Voice grant
$VoiceGrant = new VoiceGrant();
$VoiceGrant->setOutgoingApplicationSid($appSid);
$VoiceGrant->setPushCredentialSid($pushCredentialSid);
// Add grant to token
$token->addGrant($VoiceGrant);
// echo token
echo $token;
任何帮助?
答
Twilio开发人员在这里传播。
在这种情况下要做的最好的事情是确保您已经添加了访问令牌所需的所有授权。
为此,请将生成的令牌复制并粘贴到debugger here中。如果您看到授权或授权部分(如失踪身份),请确保您正确地将其传递给您的功能。
你可以输入你在[debugger here](https://jwt.io/)中获得的令牌,并遮盖任何识别信息,在此发布结果?可能有些东西丢失了,即使你的代码看起来不错,但很难说清楚。 – philnash
我认为调试器帮助解决了这个问题。这是失踪的身份。如果你把这个作为答案,我会接受 - 也谢谢 –
谢谢!我已经添加了答案。它看起来好像你通过了身份认证,但我猜'$ identity'在其他地方没有设置好。 – philnash