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.

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

报告相同问题?

悬赏问题

  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证