laravel - Laravel:无法使用自动加载功能
问题描述
我有一个关于 Laravel 自动加载的问题。
我正在尝试使用 API 来翻译网站。我在控制器中输入了提供商提供的代码,我收到了以下错误消息。
require(vendor\autoload.php):打开流失败:没有这样的文件或目录
这是代码。
require 'vendor\autoload.php'; <=★Here★
session_start();
define('URL', '');
define('KEY', '');
define('SECRET', '');
define('NAME', '');
$api_name = '';
$api_param = '';
$provider = new \League\OAuth2\Client\Provider\GenericProvider(
[
'clientId' => KEY,
'clientSecret' => SECRET,
'redirectUri' => '',
'urlAuthorize' => '',
'urlAccessToken' => URL . '/oauth2/token.php',
'urlResourceOwnerDetails' => '',
],
);
try {
// Try to get an access token using the authorization code grant.
$accessToken = $provider->getAccessToken('client_credentials');
// The provider provides a way to get an authenticated API request for
// the service, using the access token; it returns an object conforming
// to Psr\Http\Message\RequestInterface.
$params = array(
'access_token' => $accessToken->getToken(),
'key' => KEY,
'api_name' => $api_name,
'api_param' => $api_param,
'name' => NAME,
'type' => 'xml',
'xxx' => 'xxx',
);
$request = $provider->getAuthenticatedRequest(
'POST',
URL . '/api/?' . http_build_query($params),
$accessToken,
);
$response = $provider->getResponse($request);
$data = $response->getBody()->getContents();
print_r($data);
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
// Failed to get the access token or user details.
exit($e->getMessage());
}
我检查了错误消息中指出的文件,实际上 autoload.php 文件位于供应商文件夹中。我做了一些研究,发现一些网站说我应该在 composer.json 中添加一个目录,但我不太确定我应该做什么。
如果你能告诉我我做错了什么或我应该做什么,我将不胜感激。任何帮助将不胜感激,因为我尝试了多种方法都没有成功。
先感谢您。
解决方案
推荐阅读
- matlab - 在 MATLAB 中生成具有已知 PDF 表达式的随机变量
- reactjs - How to intercept message from Chatbot in a React component ? (Microsoft botframework-webchat)
- python - SSD和SSD Lite有什么区别??(Tensorflow)
- c - 矩阵的第一个索引被忽略
- python-3.x - 通过 EC2 进行 S3 身份验证,无需在代码或存储中传递 AWS 访问密钥和密钥
- javascript - 通过单击图像将文本插入输入字段
- swift - 只有一个 Swift 按钮 = 致命错误:在展开可选值时意外发现 nil
- r - 使用 R 中的 Plot 减小图例的字体大小并移动到左下角?
- java - 使用 FCM 和 Java Web API 反应原生推送通知?
- ios - iOS - 同步 Web 和应用订阅