如果我运行这个:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/AuthorizedConnectApps/CN***.json' -u "$TWILIO_CONNECTED_APP_SID:$TWILIO_CONNECTED_AUTH_TOKEN" -sS | jq
我可以看到我的应用已获得授权:
{
"connect_app_sid": "CN***",
"account_sid": "AC***1",
"permissions": [
"get-all",
"post-all"
],
"connect_app_friendly_name": "*** Dev Connect App",
"connect_app_description": "*** test account",
"connect_app_company_name": "***",
"connect_app_homepage_url": "https://***.com/",
"uri": "/2010-04-01/Accounts/AC***/AuthorizedConnectApps/CN***.json"
}
但是当我尝试使用我的应用凭据列出该帐户的所有电话号码时:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/IncomingPhoneNumbers.json' -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" -sS | jq
我明白了:
{
"code": 20003,
"detail": "",
"message": "Authenticate",
"more_info": "https://www.twilio.com/docs/errors/20003",
"status": 401
}
我不知道为什么。我知道这些凭据有效,因为我可以列出我的子帐户:
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts.json?Status=active' -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN -sS | jq
我似乎无法获得我关联帐户的任何信息。
答案 0 :(得分:1)
这里是 Twilio 开发者布道者。
当您代表通过 Twilio Connect 连接的帐户提出请求时,您应该authenticate the request with the connected account's SID but your auth token。帐户的 SID 也会进入 2010-04-01
命名空间下 API 请求的 URL。
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts/'$TWILIO_CONNECTED_APP_SID'/IncomingPhoneNumbers.json' \
-u "$TWILIO_CONNECTED_APP_SID:$TWILIO_AUTH_TOKEN" -sS | jq