symfony - 在 symfony 3 中添加 Google API 客户端库

标签 symfony google-oauth bundle google-api-php-client

我想在我的 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/

相关文章:

performance - 如何使 Symfony2 使用连接 : Keep-Alive? 返回 HTTP 响应

symfony - 在Sonata Admin实体的显示模板内添加自定义表单

oauth-2.0 - Google API/OAuth - 如何将 support@example.com 电子邮件地址用于 "Branding Information"?

混帐包 : bundle tags and heads

php - 在 Twig 模板中包含 SVG

php - 是否可以在 Doctrine 和 Symfony2 中找到使用多个值的列?

oauth - 谷歌 OAuth : Access Not Configured

google-cloud-endpoints - 使用 Google 登录网站,是否可以通过编程方式登录?

javascript - 使用 browserify 和 gulp 进行多个 bundle

xcode - Bundle 无法从 XCode 中找到复制的框架