duan198123 2019-07-27 17:23
浏览 66
已采纳

让Google客户端在Lumen中工作

I am trying to get the google api client for php to work in Lumen, however trying to create a client results in my api to give a 'Oops, something went wrong' error with no further useful information.

I think it is something to do with the way im trying to import the google api client into Lumen, i used composer to install it. But i am not sure if i am using the right thing for Lumen. If i change my require_once it would state that it could not find the 'autoload.php' in the current path. I've also tried the composer update -vvv

The Google folder is present in my vendor folder, and the composer.json also has a entry for the google/apiclient

    "require": {
        "php": ">=7.1.3",
        "google/apiclient": "2.0",
        "laravel/lumen-framework": "5.8.*"
    },
<?php

namespace App\Http\Controllers;

require_once dirname(__DIR__).'\..\..\vendor\autoload.php';

use App\Author;
use Illuminate\Http\Request;

class AccessController extends Controller
{
    private function getToken()
    {
        $credentialsFilePath = 'service_account.json';
        $client = new Google_Client();
        $client->setAuthConfig($credentialsFilePath);

        $client->addScope('https://googleapis.com/auth/analytics.readonly');
        $client->setApplicationName("GoogleAnalytics");
        $client->refreshTokenWithAssertion();
        $token = $client->getAccessToken();
        $accessToken = $token['access_token'];

        return $accessToken;
    }

    public function showAccess()
    {
        $at = getToken();

        return response('Token: ');
    }


}

As you can see im trying to get the service account access token from a json that is saved at the server (no problems). but whenever the line $client = new Google_Client(); is called, i get the 'woops, something went wrong' error from Lumen

  • 写回答

1条回答 默认 最新

  • dth8312 2019-07-28 17:36
    关注

    It appears i forgot the use Google_Client; Pretty simple but something i completely overlooked.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持