这是我的测试代码:
=========================================
<?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="540223414844-tj91ijj3u99c44bhmftb8m20tgon57hc@developer.gserviceaccount.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("lensZheng@gmail.com");
$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", "ccfsz.public@gmail.com");
?>==========================================
这是我得到的例外:
==========================================
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的认证url中获得的。
在开发人员控制台中创建新密钥时会生成browser api键。
请告诉我我的密码有什么问题?
谢谢。
我捕获了异常,它没有再次引发异常,但我仍然无法使用mAccountManager.getAccountByType("com.eyenotes").检索帐户信息在google控制台中,它表明我已经成功地请求了。另外,在Glassware.Now上切换“打开”之后,我无法获得我的应用程序,我试图在工厂重新设置我的玻璃,但是两个小时后,我没有得到任何信息表明我已经成功地重置了。(现在我的应用程序无法公开显示)
发布于 2015-01-10 00:12:40
有很多事我想知道..。首先,错误中的路径不在代码中。因此无法确定错误实际上来自何处。
关于GDK的认证也可能还有其他的问题,只是想提醒你一下.您可以暂时存储与该请求一起发送的userToken查询解析(不要永久地存储它),然后通过运行的任何后端对用户进行身份验证。从那里,你可能会要求适当的范围为他们的谷歌帐户。完成之后,您可以在PHP中正常地创建镜像服务,然后使用Account集合:
// $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);而且,您只能在APK在MyGlass上(在评审过程中发生)之后测试和使用此API。如果您还没有这样做,我还建议将镜像API PHP Quickstart作为一个起点来了解身份验证是如何工作的。
https://stackoverflow.com/questions/27794189
复制相似问题