未授权端点,请检查设置->安全->远程站点设置端点

Ram*_*h S 2 salesforce twilio

我无法通过 Twilio API 发送短信。我得到以下异常:

错误:未经授权的端点,请检查设置->安全->远程站点设置端点:url

global class SampleSMSTest {
    @future(callout=true)
    public static void testsms() {
        try {
            String account = 'xxxxxxxxx';
            String token = 'xxxxxxxxxx';
            TwilioRestClient client = new TwilioRestClient(account, token);
            Map<String, String> params = new Map<String, String> {
                'To' => '+91953835xxxx',
                'From' => '+1920569xxxx', // twilio registered number
                'Body' => 'Hello there!'
            };
            TwilioMessage message = client.getAccount().getMessages().create(params);
        } catch (Exception e) {
            System.debug('Main error==========>' + e);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Ram*_*h S 6

在沙箱中添加 Twilio URL 作为以下路径

Administration Setup  > Security Controls > Remote Site Settings > click "**New Remote Site**" button.
Run Code Online (Sandbox Code Playgroud)

我已经重新解决了我的问题


小智 5

这看起来像 Salesforce APEX 代码。无论何时您想要从 Salesforce 调用外部 URL,您都需要将该 URL 设置为安全的远程站点。错误消息会告诉您在 SF 中的确切位置。将 Twilio URL“api.twilio.com”添加到列表中。