我想在我的 symfony 3 项目中安装“Google API 客户端库”,但我不知道如何使用它。
我使用以下命令从“https://github.com/googleapis/google-api-php-client#download-the-release ”安装库:
Composer 需要 google/apiclient:"^2.0"
接下来,我尝试在 AppKernel.php 文件“bundles”数组中添加 namespace ,但我不知道 namespace 是什么或在哪里可以找到 namespace 。然后我每次都会收到这个错误:
Attempted to load class "Google_Client" from namespace "AppBundle\Controller".
这是我的小功能:
/**
* @Route("/api/oAuth/login", name="api_oauth_login")
*/
public function oAuthLoginAction(Request $request)
{
$client = new Google_Client();
$client->setApplicationName("My Application");
$client->setDeveloperKey("MY_SIMPLE_API_KEY");
}
有人可以帮助我集成这个库吗?
最佳答案
该库不使用命名空间,因此您应该在类名之前使用尾部斜杠来引用该类,例如:
$client = new \Google_Client();
关于symfony - 在 symfony 3 中添加 Google API 客户端库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52814434/