我正在尝试与laravel google社交名流驱动程序合作,在那里我需要使用api调用获得的访问令牌从google获取用户数据。
但当我认为我做的每件事都是正确的时候,这就是一个错误
说
Call to protected method Laravel\\Socialite\\Two\\GoogleProvider::getUserByToken()
我理解它说我无法访问该方法,因为它保护。
那么如何绕过这个问题呢。
我的目标
我的目标是验证我从我的移动应用程序中获得的社交访问(基本上是谷歌)令牌,并将该用户的数据存储到我从社交名媛那里收到的数据库中
我的路线
api.php
Route::post('login','api\unAuthApiCall@index');
我的控制器
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Laravel\Socialite\Facades\Socialite;
class unAuthApiCall extends Controller
{
public function index(Request $request){
$authToken= Input::get('auth_token');
$driver = Socialite::driver('google');
$socialUserObject= $driver->getUserByToken($authToken);
return json_encode($socialUserObject);
}
}
我得到的回应
{
"message": "Call to protected method Laravel\\Socialite\\Two\\GoogleProvider::getUserByToken() from context 'App\\Http\\Controllers\\api\\unAuthApiCall'",
"exception": "Symfony\\Component\\Debug\\Exception\\FatalThrowableError",
"file": "C:\\Users\\CODED\\Documents\\laravelSocilte\\app\\Http\\Controllers\\api\\unAuthApiCall.php",
"line": 28,
"trace": [
{
"function": "index",
"class": "App\\Http\\Controllers\\api\\unAuthApiCall",
"type": "->"
}