2012-06-19 6 views
-1

임 "서비스 계정"과 캘린더 응용 프로그램을 만들려고하고 나는 구글-API-PHP 클라이언트Google 캘린더 API - 서비스 계정 오류

을의 최신 버전을 다운로드 그리고 내가 serviceAccount.php에 액세스 할 때 내가 얻을 다음과 같은 오류 :

치명적인 오류 : 정의되지 않은 방법 apiClient에 전화 :: /home/fmentert/public_html/reservations/google-api-php-client/examples/calendar/serviceAccount.php에서 setAssertionCredentials을() 라인에서 44

이것은 내 serviceAccount.php 파일입니다. 내 고객 ID, 서비스 계정 이름 및 키 파일을 추가했습니다. 또한. 나는 내 PHP 버전은 5.2.17

가 는
define('CLIENT_ID', '896988357842.apps.googleusercontent.com'); 
define('SERVICE_ACCOUNT_NAME', '[email protected]'); 

// Make sure you keep your key.p12 file in a secure location, and isn't 
// readable by others. 
define('KEY_FILE', 'bqwe3287e42d1c2342349f4c9769asdas55-privatekey.p12'); 

$client = new apiClient(); 
$client->setApplicationName("Google Prediction Sample"); 

// Set your cached access token. Remember to replace $_SESSION with a 
// real database or memcached. 
session_start(); 
if (isset($_SESSION['token'])) { 
$client->setAccessToken($_SESSION['token']); 
} 

// Load the key in PKCS 12 format (you need to download this from the 
// Google API Console when the service account was created. 
$key = file_get_contents(KEY_FILE); 
$client->setAssertionCredentials(new apiAssertionCredentials( // THIS IS LINE 44 
    SERVICE_ACCOUNT_NAME, 
    array('https://www.googleapis.com/auth/prediction'), 
    $key) 
); .... 

이 사람이 잘못 알고 있나요()의 정의 const를 변경?

+0

게시 한 코드가 잘못된 URL에서 토큰을 받으려고합니다. https://www.googleapis.com/auth/prediction URL은 예측 서비스를위한 것입니다. 캘린더 서비스의 경우 https://www.googleapis.com/auth/calendar가 필요합니다. 아래의 응답에서 우리는 apiClient.php 파일을 포함하고 src/contrib/apiCalendarService.php 파일에 ADD를 추가해야합니다. 코드를 읽으면 메모를 읽거나 찾고있는 코드를 붙여 넣을 수 있다고 추측합니다. 당신의 목적에 부합하는 코드의 논리에 – IberoMedia

답변

0

apiClient 클래스에 대한 정의가 포함 된 파일이 포함되지 않은 것처럼 보입니다. 이 경우 require_once 명령을 사용하십시오. apiClient 클래스는, "apiClientFile.php"라는 파일에 정의되어있는 경우

예를 들어, 다음의 PHP 스크립트는 다음과 같습니다

require_once 'apiClientFile.php'; 

define('CLIENT_ID', '896988357842.apps.googleusercontent.com'); 
... 
+0

안녕하세요. 나는 실제로 여기에 덧붙여 모든 코멘트와 함께 여기에 붙여 넣지 않았다. 그래서 그것은 ....로 시작합니다. comments, comments, comments -> require_once '../../src/apiClient.php'; require_once '../../src/contrib/apiPredictionService.php'; 그리고 최신 버전을 찾았습니다 –

+0

글쎄, 오류 메시지는 "apiClient"클래스에서 "setAssertionCredentials"라는 메서드를 찾을 수 없다고 말합니다. apiClient.php를 열어 필요한 방법을 찾을 수 있는지보십시오. 잘못된 메서드 이름을 사용하고있는 것일 수 있습니다. – Michael

+0

고맙다 --- 아하. 예, 맞았습니다 ... 나는 최신 버전 에서 setAssertionCredentials를 찾을 수 없습니다. http://code.google.com/p/google-api-php-client/ 그리고 " 소스 ": http://code.google.com/p/google-api-php-client/source/browse/trunk/src/apiClient.php?r=399 올바른 파일을 가져 왔지만 나는 그들을 하나씩 다운로드해야만한다. 문제인가? (하나씩) 이제 다른 오류가 발생합니다. –

1

문제는 라스 버전이다. 거기서 해결책을 얻을 수 있습니다 : https://groups.google.com/forum/#!msg/google-api-php-client/vZysbW_XgiQ/-4kSFWP8UtEJ%5B1-25%5D

475 버전을 사용하여 수정했습니다. 그것으로 예제는 잘 동작합니다.

Salut!

+0

이 링크는 질문에 대한 답변 일지 모르지만 여기에 답변의 핵심 부분을 포함하고 참조 할 수있는 링크를 제공하는 것이 좋습니다. 링크 된 페이지가 변경되면 링크 전용 답변이 유효하지 않게 될 수 있습니다. –