2014-01-16 3 views
0

EDIT 이 오류는 응용 프로그램을 올바르게 설정하지 않았기 때문에 발생했습니다. 코드가 지금도 작동하지만 문제가 무엇인지 알 수없는 상황입니다. 문제를 파악하기 위해 내부 작업에 깊이 관여해야합니다. 원인 : 오류 Google_OAuth2.php on line 115

Windows7 운영 체제 명령 줄에서 PHP 용 Google 드라이브 API 퀵 스타트 예제 코드를 실행 중입니다. 나는 성공적으로 내 액세스 토큰을 반환 승인 URL을 획득을 통해 얻을 수

Google Drive API Quick Start

: 여기가 실행하고있는 코드입니다. 그러나 액세스 토큰을 입력 한 후 승인을 완료하기 위해 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 파일에서 코드의 일부입니다 : 여기

이 더 완전한 오류 MSG입니다 라인 (115)은 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는 변경하지 않아야합니다. 나는이 시점에서이 작품을 어떻게 만들지 모른다.

답변

1

Google에서 마침내 예제 코드를 실행할 수있었습니다. 문제는 내가 잘못된 클라이언트 ID와 클라이언트 비밀 키를 사용하고 있었다고 생각합니다. 음, 실제로 잘못된 Client ID Credential 응용 프로그램 유형을 모두 사용하고있었습니다. 나는 을 installed application으로 사용하고 있었다고 생각합니다. 글쎄, 내 오류, 그리고 API에 문제가 아니 기쁘다. Native ApplicationInstalled Application입니다. 나는이 용어들이 서로 교환되어 사용된다고 생각한다. 그리고 은 Command Line에서 PHP를 실행하기위한 것입니다. 또 다른 사실은 클라이언트 ID가 Native Application 생성되면 리디렉션 URI를 변경할 수 없다는 것입니다. 자동으로 다음과 같이 설정됩니다.

urn:ietf:wg:oauth:2.0:oob 
http://localhost 
관련 문제