我使用了 TwitterOAuth 库并得到了这个错误

I used the TwitterOAuth library and got this error

Fatal error: Uncaught Error: Class 'Composer\CaBundle\CaBundle' not found in 
C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php:572 Stack trace: 
#0 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(620): Abraham\TwitterOAuth\TwitterOAuth->curlOptions() 
#1 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(557): Abraham\TwitterOAuth\TwitterOAuth->request('https://api.twi...', 'GET', 'Authorization: ...', Array, false) 
#2 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(490): Abraham\TwitterOAuth\TwitterOAuth->oAuthRequest('https://api.twi...', 'GET', Array, false) 
#3 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(467): Abraham\TwitterOAuth\TwitterOAuth->makeRequests('https://api.twi...', 'GET', Array, false) 
#4 C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php(232): Abraham\TwitterOAuth\TwitterOAuth->http('GET', 'h in C:\xampp\htdocs\CompleteWDC\cha10_APIs\twitter-api\twitteroauth\src\TwitterOAuth.php on line 572

我是第一次使用它,所以检查了 TwitterOAuth.php 文件和第 572 行然后 vscode 说 CaBundle 是未定义类型 未定义类型 'Composer\CaBundle\CaBundle'. ,我尝试一遍又一遍地下载文件,但同样的错误。

按照 here 上的说明,我遇到了完全相同的问题。

事实证明我没有包括正确的自动加载。对于遇到同样问题的人:

  1. 按照这些 instructions.
  2. 在您的目录中本地安装 composer
  3. 运行 php composer require abraham/twitteroauth.
  4. 运行 php composer install.
  5. 确保在您的 PHP 代码 require "vendor/autoload.php";.
  6. 中包含 composer 自动加载器文件的正确路径,而不是包自动加载器
  7. 在您将使用该包的每个文件中,不要忘记包含行 use Abraham\TwitterOAuth\TwitterOAuth as TwitterOAuth;,以便您可以使用 $foo = new TwitterOAuth();

我希望这对像我这样的作曲家新手有所帮助。