我根本不明白整個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 (省略祕密,很明顯)