I'm trying to use Laravel Socialite package over an api. I try to pass the code into my api to fetch the user but it keeps giving me an error:

Fatal error: Call to a member function pull() on null

由于我是通过API进行请求的,所以我采取以下步骤.

Send a request to api for the url to fetch the code:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()

然后使用上面获取的URL发出请求,该URL使用code参数重定向.

Send the code to the api and fetch the user:

$fb_user = Socialite::with('facebook')->user();

This is where it crashes. I'm not sure why.

I've used the package before and it works fine when I just have an app that reloads the page. But when I send it to an api (on a different domain) it crashes. I'm thinking there is some issue with how the code is generated. Is there anyway to fix this?

推荐答案

刚刚找到我的答案.两次通话都需要使用stateless:

Socialite::with('facebook')->stateless()->redirect()->getTargetUrl()

$fb_user = Socialite::with('facebook')->stateless()->user();

希望这能帮到什么人.

Laravel相关问答推荐

如何在 Laravel 中使用多对一变形关系

无法在 Laravel 项目中安装 @vitejs/plugin-vue

在 laravel 5.3 中截断的错误日志(log)

基于数据表 Laravel 4 导出 CSV 或 PDF

自定义 Laravel 关系?

在laravel中将数据插入数据透视表

Laravel + SQLite = SQLSTATE[HY000]一般错误:8次try 写入只读数据库

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

在 laravel 如何将额外的数据传递给 mutators 和 accessors

Laravel 5 - Php artisan语法错误

如何在 Laravel 中创建类别的嵌套列表?

Heroku CLI 安装错误:PATH 未更新,原始长度 1585 > 1024

Composer 致命错误:声明 Fxp... 必须与第 334 行的 ...AbstractAssetsRepository.php 兼容

Laravel - 更新时禁用更新时间

将自定义消息(或任何其他数据)传递给 Laravel 404.blade.php

如何从 Laravel 中的资源中获取图像?

在 Laravel 4 中使用 HTML 占位符

如何使 Laravel (Blade) 文本字段只读

以编程方式而不是从 CLI 运行 Laravel 5 seeder

Laravel 将附加参数传递给函数