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

2023-09-06 06:07:28 作者:年华何日不离伤

我需要在postBody插入镜API插入方法用户的电子邮件。我用这code:

I need to insert user's email in postBody of mirror API insert method. I am using this code:

$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。

The above method returns null in response! I am not sure what to add as authtoken.

在此,我需要通过Android的客户经理来获取用户的电子邮件帐户:

After this, I need to retrieve user's email account through Android's account manager:

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

似乎这不工作。我不明白这种类型的玻璃设备的帐户。任何帮助将是巨大的。

This doesn't seem to work. I do not get accounts of this type in Glass device. Any help will be great.

编辑: 增加了authTokenArray和userDataArray以postBody以下的建议:

Added the authTokenArray and userDataArray to postBody as suggested below:

$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);

帐户insert方法仍然返回null。无法解决的问题到现在。

Account insert method still returns null. Unable to solve the issue till now.

[求助] 镜子API仍然返回NULL响应,但帐户实际上是被插入镜API。更新code可以在这里查看: http://goo.gl/DVggO6

[SOLVED] Mirror API still returns NULL response, but account is actually being inserted in Mirror API. Updated code can be viewed here: http://goo.gl/DVggO6

推荐答案

setAuthTokens 需要 Google_Service_Mirror_AuthToken 的数组对象(看到源这里),每一种都有自己选择的的authToken (任意的字符串)和键入(另一种任意的字符串)。这些值直接复制到了Android上的帐户的AccountManager ,这样你可以看看他们在设备上。

setAuthTokens takes an array of Google_Service_Mirror_AuthToken objects (see the source here), each of which has an authToken (an arbitrary string of your choosing) and a type (another arbitrary string). These values are copied directly into the account in the Android AccountManager so that you can look them on the device.

您的问题可能会从你正在传递对于现在的事实来了。我会尝试修复那些再看看,如果你能看到设备上的帐户。

Your problem might be coming from the fact that you're passing in null for that right now. I would try fixing that and then see if you're able to see the account on the device.