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

我需要在postBody of mirror API insert方法中插入用户的电子邮件.我正在使用此代码

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

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

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

$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仍然返回NULL响应,但实际上是在Mirror API中插入了帐户.更新后的代码可在此处查看:http://goo.gl/DVggO6

解决方法:

setAuthTokens获取一组Google_Service_Mirror_AuthToken对象(see the source here),每个对象都有一个authToken(您选择的任意字符串)和一个类型(另一个任意字符串).这些值将直接复制到Android AccountManager中的帐户中,以便您可以在设备上查看它们.

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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...