如何插入和检索postBody在镜像API帐户插入方法使用PHP


How to insert and retrieve postBody in Mirror API account insert method using PHP

我需要在镜像API插入方法的postBody中插入用户的电子邮件。我正在使用这个代码:

$authtoken=null;    
$postBody = new Google_Service_Mirror_Account();
$postBody->setAuthTokens($authtoken);
$userdata=array("email"=>$email);
$postBody->setUserData($userdata);
$account = $service->accounts->insert($userToken, package-name-here, $accountName, $postBody);

上面的方法在响应中返回null !我不确定要添加什么作为authtoken。

之后,我需要通过Android的帐户管理器检索用户的电子邮件帐户:

AccountManager manager = AccountManager.get(c);
Account[] list = manager.getAccountsByType(package-name-here);
for (Account acct : list) {
    accountEmailId= manager.getUserData(acct, "email");
    break;           
}

这似乎不起作用。我没有在谷歌眼镜设备中得到这种类型的账户。任何帮助都太好了。

编辑:为postBody添加authTokenArray和userDataArray,如下所示:

$userDataArray= array();
$userData1= new Google_Service_Mirror_UserData(); 
$userData1->setKey('email');
$userData1->setValue($email);
$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);

帐户插入方法仍然返回null。目前还无法解决这个问题。

(解决)镜像API仍然返回NULL响应,但帐户实际上被插入到镜像API中。更新后的代码可以在这里查看:http://goo.gl/DVggO6

setAuthTokens接受一个Google_Service_Mirror_AuthToken对象数组(参见这里的源代码),每个对象都有一个authToken(您选择的任意字符串)和一个type(另一个任意字符串)。这些值直接复制到Android AccountManager中的帐户中,以便您可以在设备上查看它们。

你的问题可能来自于你现在正在通过null的事实。我会尝试解决这个问题,然后看看你是否能在设备上看到账户。