在 laravel 包中获取错误 json 令牌无效
Getting error invalid json token in laravel package
当前实现了一个google驱动API.Getting错误无效json令牌在laravelpackage.I想要在 google 驱动器中创建文件夹后上传文件。创建的应用程序可以正常工作,但重定向后什么也没有发生。如果有人能帮忙。
**教程Link**:https://www.sitepoint.com/is-laravel-good-enough-to-power-a-custom-google-drive-ui/
可能是软件包已弃用
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Googl;
class HomeController extends Controller
{
public function index()
{
return view('login');
}
public function login(Googl $googl, Request $request)
{
$client = $googl->client();
if ($request->has('code')) {
$client->authenticate($request->input('code'));
$token = $client->getAccessToken();
$plus = new \Google_Service_Plus($client);
$google_user = $plus->people->get('me');
$id = $google_user['id'];
$email = $google_user['emails'][0]['value'];
$first_name = $google_user['name']['givenName'];
$last_name = $google_user['name']['familyName'];
session([
'user' => [
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
'token' => $token
]
]);
return redirect('/dashboard')->with('message', ['type' => 'success', 'text' => 'You are now logged in.']);
} else {
$auth_url = $client->createAuthUrl();
return redirect($auth_url);
}
}
}
堆栈跟踪:
第一次检查:
从您链接到的教程(我没有看到它,我假设这就是您所拥有的)看起来 AdminController 构造函数正在尝试从 user.token 会话变量中检索令牌。值得在使用之前检查它是否确实包含一个令牌。
尝试一下:
回顾我几个月前的实现,我似乎很难从 Google 客户端检索正确的令牌字符串。而不是:
if ($request->has('code')) {
...
$token = $client->getAccessToken();
...
试试这样的东西:
if ($request->has('code')) {
$fullToken = $client->fetchAccessTokenWithAuthCode($code);
$client->setAccessToken($fullToken);
这应该是一个评论,但我似乎还不能...
从您的屏幕截图中,我可以看出问题出在 AdminController.php 的 第 16 行 中。你能分享这个代码吗? setAccessToken()
正在接收 null
对象,所以问题出在这里。
当前实现了一个google驱动API.Getting错误无效json令牌在laravelpackage.I想要在 google 驱动器中创建文件夹后上传文件。创建的应用程序可以正常工作,但重定向后什么也没有发生。如果有人能帮忙。
**教程Link**:https://www.sitepoint.com/is-laravel-good-enough-to-power-a-custom-google-drive-ui/
可能是软件包已弃用
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Googl;
class HomeController extends Controller
{
public function index()
{
return view('login');
}
public function login(Googl $googl, Request $request)
{
$client = $googl->client();
if ($request->has('code')) {
$client->authenticate($request->input('code'));
$token = $client->getAccessToken();
$plus = new \Google_Service_Plus($client);
$google_user = $plus->people->get('me');
$id = $google_user['id'];
$email = $google_user['emails'][0]['value'];
$first_name = $google_user['name']['givenName'];
$last_name = $google_user['name']['familyName'];
session([
'user' => [
'email' => $email,
'first_name' => $first_name,
'last_name' => $last_name,
'token' => $token
]
]);
return redirect('/dashboard')->with('message', ['type' => 'success', 'text' => 'You are now logged in.']);
} else {
$auth_url = $client->createAuthUrl();
return redirect($auth_url);
}
}
}
堆栈跟踪:
第一次检查:
从您链接到的教程(我没有看到它,我假设这就是您所拥有的)看起来 AdminController 构造函数正在尝试从 user.token 会话变量中检索令牌。值得在使用之前检查它是否确实包含一个令牌。
尝试一下:
回顾我几个月前的实现,我似乎很难从 Google 客户端检索正确的令牌字符串。而不是:
if ($request->has('code')) {
...
$token = $client->getAccessToken();
...
试试这样的东西:
if ($request->has('code')) {
$fullToken = $client->fetchAccessTokenWithAuthCode($code);
$client->setAccessToken($fullToken);
这应该是一个评论,但我似乎还不能...
从您的屏幕截图中,我可以看出问题出在 AdminController.php 的 第 16 行 中。你能分享这个代码吗? setAccessToken()
正在接收 null
对象,所以问题出在这里。