如何使用PHP在Mirror API账户插入方法中插入和检索postBody[英] How to insert and retrieve postBody in Mirror API account insert method using PHP

本文是小编为大家收集整理的关于如何使用PHP在Mirror API账户插入方法中插入和检索postBody的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我需要在镜像API插入方法的帖子中插入用户的电子邮件.我正在使用此代码:

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

上面的方法返回响应零!我不确定要添加什么作为authtoken.

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

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

这似乎不起作用.我没有在玻璃设备中获得这种类型的帐户.任何帮助都会很棒.

编辑: 如下所示,添加了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.到目前为止无法解决问题.

[已解决] Mirror API仍然返回无效响应,但实际上将帐户插入了Mirror API中.可以在此处查看更新的代码: http://goo.gl/dvggo6

推荐答案

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

您的问题可能来自您现在传递null的事实.我会尝试修复该问题,然后查看您是否可以在设备上看到帐户.

本文地址:https://www.itbaoku.cn/post/102521.html

问题描述

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

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

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.

EDIT: 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);

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

[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 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.