我正在为Laravel 5 OAuth实现oriceon/oauth-5-laravel服务提供商
我收到了这个错误“调用未定义的方法OAuth::this ()”。我遵循自述安装步骤:
以下是我的config/oauth-5-laravel.php:
return [
/*
|--------------------------------------------------------------------------
| oAuth Config
|--------------------------------------------------------------------------
*/
/**
* Storage
*/
'storage' => '\\OAuth\\Common\\Storage\\Session',
/**
* Consumers
*/
'consumers' => [
'Facebook' => [
'client_id' => '',
'client_secret' => '',
'scope' => [],
],
'Google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_SECRET_ID'),
'scope' => ['userinfo_email', 'userinfo_profile'],
],
]
];这是我的GoogleController.php:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use OAuth;
class GoogleController extends Controller
{
public function loginWithGoogle(Request $request)
{
// get data from request
$code = $request->get('code');
// get google service
$googleService = \OAuth::consumer('Google');
// check if code is valid
// if code is provided get user data and sign in
if ( ! is_null($code))
{
// This was a callback request from google, get the token
$token = $googleService->requestAccessToken($code);
// Send a request with it
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message. "<br/>";
//Var_dump
//display whole array.
dd($result);
}
// if not ask for permission first
else
{
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to google login url
return redirect((string)$url);
}
}
}发布于 2016-11-11 14:17:00
问题是在php中是类OAuth,它是在oriceons OAuth之后被初始化的。
https://stackoverflow.com/questions/40461932
复制相似问题