2015-01-06 6 views
0

를이 내 테스트 코드 사용 ========GDK 인증 PHP

<?php 

include_once "templates/base.php"; 
session_start(); 

require_once realpath(dirname(__FILE__) . '/../autoload.php'); 

function get_service_client(){ 
$service_client_id="540223414844-tj91ijj3u99c44bhmftb8m20tgon57hc.apps.googleusercontent.com"; 
$service_email="[email protected]account.com"; 
$app_name="Eyenotes"; 
$key_file_location='C:/Users/Yuan/Desktop/eyenotes-81e92b7df1f1.p12'; 
$browser_api_key="AIzaSyAplINlgfGWGJ8pD1Bxlr8wg7i8ZNVOS1A"; 

$client = new Google_Client(); 
$client->setApplicationName("Eyenotes"); // Set your application name 
$client->setClientId("540223414844-tj91ijj3u99c44bhmftb8m20tgon57hc.apps.googleusercontent.com"); 
$client->setDeveloperKey("AIzaSyAplINlgfGWGJ8pD1Bxlr8wg7i8ZNVOS1A"); 
$key = file_get_contents("C:/Users/Yuan/Desktop/eyenotes-81e92b7df1f1.p12"); 
$cred = new Google_Auth_AssertionCredentials(
$service_email,array('https://www.googleapis.com/auth/glass.thirdpartyauth'),$key 
); 
$client->setAssertionCredentials($cred); 
return $client; 
} 

function insert_account($service,$userToken, $email) 
{ 
$accountType='com.eyenotes'; 
$userDataArray= array(); 
$userData1= new Google_Service_Mirror_UserData(); 
$userData1->setKey('email'); 
$userData1->setValue("[email protected]"); 
$userDataArray[]=$userData1; 
$authTokenArray= array(); 
$authToken1= new Google_Service_Mirror_AuthToken(); 
$authToken1->setAuthToken('randomtoken'); 
$authToken1->setType('randomType'); 
$authTokenArray[]=$authToken1; 
$postBody = new Google_Service_Mirror_Account(); 
$postBody->setUserData($userDataArray); 
$postBody->setAuthTokens($authTokenArray); 
try { 
$account = $service->accounts->insert($userToken, $accountType, $email, $postBody); 
echo $account; 
} catch (Exception $e) { 

} 
} 
$service_client= get_service_client(); 
$mirrorService = new Google_Service_Mirror($service_client); 
insert_account($mirrorService, "6164da1732ea09b4", "[email protected]"); 
?> 

===================================

============================ : =======

이 내가 가진 예외입니다 ==============

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/mirror/v1/accounts/6164da1732ea09b4/com.eyenotes/ccfsz.public%40gmail.com?key=AIzaSyDxnl16J8Eiwv00k_1yzw_VoRr9wD32qao: (400) Invalid Value' in D:\MySoftware\wamp\www\insert\src\Google\Http\REST.php on line 111 
Google_Service_Exception: Error calling POST https://www.googleapis.com/mirror/v1/accounts/6164da1732ea09b4/com.eyenotes/ccfsz.public%40gmail.com?key=AIzaSyDxnl16J8Eiwv00k_1yzw_VoRr9wD32qao: (400) Invalid Value in D:\MySoftware\wamp\www\insert\src\Google\Http\REST.php on line 111 

======================= 매개 변수 설명 :

계정 유형이 Google에 제공됩니다.

사용자 토큰은 내가 Google에 제공하는 인증 URL에서 가져 왔습니다.

개발자 콘솔에서 새 키를 만들 때 브라우저 api 키가 생성됩니다.

내 코드에서 어떤 점이 문제인지 말해 주시겠습니까?

감사합니다.

예외가 발생하여 예외가 다시 발생하지는 않지만 mAccountManager.getAccountByType ("com.eyenotes")을 사용하여 계정 정보를 검색 할 수 없습니다. 그리고 Google 개발자 콘솔에서 성공적으로 요청한 것을 보여줍니다. 또 하나, Glassware에서 "ON"으로 전환 한 후 응용 프로그램을 가져올 수 없습니다. 이제는 글래스를 공장 초기화하려고합니다.하지만 2 시간이 지나면 다시 설정 한 것을 나타내는 정보를 얻지 못했습니다. (이제는 내 응용 프로그램이 공개적으로 표시되지 않습니다.)

답변

0

내가 알고 싶은 많은 것들이 있습니다. 첫째, 오류의 경로는 코드에 없습니다. 따라서 오류가 실제로 어디에서 왔는지 확신 할 수 없습니다.

GDK의 인증과 관련하여 다른 문제가있을 수 있습니다. 단지 요청을 보내면 userToken 쿼리 매개 변수를 임시로 저장할 수 있습니다 (영구적으로 저장하지 않음). 실행중인 백엔드에 의해 사용자를 인증하십시오. 그런 다음 Google 계정의 적절한 범위를 요청할 가능성이 큽니다. 가입 한 후에는 PHP에서 정상으로 당신의 거울 서비스를 만들고 사용하는 계정 수집 할 수 있습니다

// $myClient would contain the typical Google_Client() setup 
// See PHP quickstart for example 
$myMirrorService = new Google_Service_Mirror($myClient); 

// Set your inputs to insert() as needed 
$accounts = $myMirrorService->accounts->insert($userToken, $accountType, $accountName, $postBody); 

을 또한, 당신은 단지 테스트와시 발생하는 (MyGlass에 APK 착륙 후이 API를 사용할 수 있습니다 검토 과정). 아직 인증을하지 않은 경우 인증 작동 방식을 이해하기 위해 시작 지점으로 Mirror API PHP Quickstar을 권장합니다.

+0

정말 고맙습니다. 답변을 주셔서 감사합니다. 대단히 감사합니다. 다시 확인하고 다시 시도해 보겠습니다. – alens

+0

안녕하세요. 나는 예외를 잡았고 다시 예외를 발생시키지 않았지만 mAccountManager.getAccountByType ("com.eyenotes");을 사용하여 계정 정보를 검색 할 수 없었다. Google 개발자 콘솔에서 성공적으로 요청한 것을 보여줍니다. 또 하나, Glassware.now에서 "ON"으로 토글 한 후 내 응용 프로그램을 가져올 수 없습니다. 내 유리를 공장 초기화하려고합니다.하지만 두 시간이 지나면 다시 설정 성공을 나타내는 정보를 얻지 못했습니다. (이제 내 응용 프로그램이 공개적으로 표시되지 않습니다). – alens