EDIT 이 오류는 응용 프로그램을 올바르게 설정하지 않았기 때문에 발생했습니다. 코드가 지금도 작동하지만 문제가 무엇인지 알 수없는 상황입니다. 문제를 파악하기 위해 내부 작업에 깊이 관여해야합니다. 끝원인 : 오류 Google_OAuth2.php on line 115
Windows7 운영 체제 명령 줄에서 PHP 용 Google 드라이브 API 퀵 스타트 예제 코드를 실행 중입니다. 나는 성공적으로 내 액세스 토큰을 반환 승인 URL을 획득을 통해 얻을 수
: 여기가 실행하고있는 코드입니다. 그러나 액세스 토큰을 입력 한 후 승인을 완료하기 위해 Google에서 제공 한`Google_OAuth2.php 파일에 문제가 있습니다.
Fatal error:
Uncaught exception 'Google_AuthException' with message 'Error fetching OAuth2 access token,
message: 'invalid_request'' in C:\google-api-php-client\src\auth\Google_OAuth2.php:115 Stack trace:
#0 C:\google-api-php-client\src\Google_Client.php(127): Google_OAuth2->authenticate(Array, '4/HW2t_MZIxatq6...')
#1 C:\Users\Gigabyte\MyWebsite\Take_Validation.php(10): Google_Client->authenticate('4/HW2t_MZIxatq6...')
#2 {main} thrown in C:\google-api-php-client\src\auth\Google_OAuth2.php on line 115
이것은 Google_OAuth2.php
파일에서 코드의 일부입니다 : 여기
throw new Google_AuthException
/**
* @param $service
* @param string|null $code
* @throws Google_AuthException
* @return string
*/
public function authenticate($service, $code = null) {
if (!$code && isset($_GET['code'])) {
$code = $_GET['code'];
}
if ($code) {
// We got here from the redirect from a successful authorization grant, fetch the access token
$request = Google_Client::$io->makeRequest(new Google_HttpRequest(self::OAUTH2_TOKEN_URI, 'POST', array(), array(
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $this->redirectUri,
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret
)));
if ($request->getResponseHttpCode() == 200) {
$this->setAccessToken($request->getResponseBody());
$this->token['created'] = time();
return $this->getAccessToken();
} else {
$response = $request->getResponseBody();
$decodedResponse = json_decode($response, true);
if ($decodedResponse != null && $decodedResponse['error']) {
$response = $decodedResponse['error'];
}
throw new Google_AuthException("Error fetching OAuth2 access token, message: '$response'", $request->getResponseHttpCode());
}
}
은 분명히 오류가 라인 앞에 오는 마지막 문장을하다 115. 라인 115는 이전에 어딘가에서 오류가 발생했다는 것을 인쇄하고 있습니다. 그것이 코드인지 또는 내가 잘못하고있는 것인지 알 수 없습니다. 새로운 URL 인증 요청이 들어올 때마다 다른 액세스 코드가 다시 생성된다는 것을 알고 있습니다. 내 고객의 비밀 번호와 클라이언트 ID는 변경하지 않아야합니다. 나는이 시점에서이 작품을 어떻게 만들지 모른다.