gpt4 book ai didi

php - 将 Twilio 与 Symfony2 集成

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:59:10 25 4
gpt4 key购买 nike

好吧,这真的让我头疼!我正在尝试将 Twilio 与 Symfony2 站点集成,并且我发现了一个显然适合此处框架的包:https://github.com/fridolin-koch/VreshTwilioBundle然而,主要的 Twilio 框架需要单独下载,并且结构与 Symfony2 不一致,因为类名不同并且不包含 namespace 。我通过 composer 安装了这个包,这似乎有效,但我经常收到这样的错误:

The autoloader expected class "Vresh\TwilioBundle\Services_Twilio" to be defined in file "/Applications/MAMP/htdocs/my_site_name/src/Vresh/TwilioBundle/Services/Twilio.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

即使声明了正确的命名空间,我也无法让它工作。我觉得我在兜圈子编辑类(class)和更改我并不真正了解的代码;如果其他人成功地将 Twilio 与 Symfony2 集成,我将不胜感激任何提示或帮助!甚至 Twilio 帮助台对 Symfony 也一无所知!

提前谢谢你迈克尔

最佳答案

我们正在成功使用 Twilio。但是我们不必单独下载它。 VreshTwilioBundle 是制作 twilio/sdk 的包装器在 Symfony 中可用。我们所做的只是:

  • 将此添加到 composer.json

    "require": {
    "vresh/twilio-bundle": "dev-master",
    }
  • AppKernel.php 中启用它

    $bundles = array(
    // ... other bundles
    new Vresh\TwilioBundle\VreshTwilioBundle(),
    );
  • 将配置添加到config.yml

    vresh_twilio:
    #(Required) Your Account SID from www.twilio.com/user/account
    sid: 'XXXXXXXX'
    #(Required) Your Auth Token from www.twilio.com/user/account
    authToken: 'YYYYYYYY'
    #(Optional, default: '2010-04-01') Twilio API version
    version: '2008-08-01'
    #(Optional, default: 1) Number of times to retry failed requests
    retryAttempts: 3

基本上,我们只是按照说明安装 VreshTwilioBundle。此 bundle 添加了 twilio/sdk 包作为其要求,因此当您运行 composer update 时会自动下载 twilio/sdk

这就是我们所要做的。然后,twilio/sdk 通过容器作为服务可用:

    $twilio = $this->get('twilio.api');

关于php - 将 Twilio 与 Symfony2 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24304558/

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