我根本不明白整个OAuth认证的工作原理,而且我几乎陷入了困境。我试图让用户使用Google PHP客户端API向我的服务器验证他/她的YouTube帐户。YouTube API OAuth无效请求
这里是我当前的代码:
<?php
require_once app_path().'/google-apis/Google_Client.php';
require_once app_path().'/google-apis/contrib/Google_YouTubeService.php';
class SignupController extends BaseController {
public function showSignupForm() {
$client = new Google_Client();
$client->setClientId('CLIENTID');
$client->setClientSecret('CLIENTSECRET');
$client->setAccessType('offline');
$client->setDeveloperKey('DEVKEY');
$youtube = new Google_YoutubeService($client);
$client->authenticate(Input::get('code'));
$token = json_decode($client->getAccessToken());
return View::make('signup')->with('google_token', $token->access_token);
}
public function getYTAccess() {
$client = new Google_Client();
$client->setClientId('CLIENTID');
$client->setClientSecret('CLIENTSECRET');
$client->setAccessType('offline');
$client->setDeveloperKey('DEVKEY');
$client->setRedirectUri('REDIRECT_URI');
$youtube = new Google_YoutubeService($client);
$authUrl = $client->createAuthUrl();
return View::make('connect_youtube')->with('authUrl', $authUrl);;
}
}
?>
这是在基于Laravel应用程序我建立了SignupController的代码。相关的路线如下:
Route::get('signup/connect_youtube/return', '[email protected]');
Route::get('signup', '[email protected]');
我只被重定向到我的应用程序后,得到一个无效的请求错误,我知道它是与访问令牌,只是不知道是什么。
任何帮助,将不胜感激。
感谢
托比亚斯Timpe (省略秘密,很明显)