How to insert and retrieve postBody into the Mirror API account insertion method using PHP

I need to insert the user's email address in the postBody method for the mirrored API. 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 that, I need to get the email user account through the Android 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 does not work. I do not receive bills of this type in a glass device. Any help would be great.

EDIT: Added authTokenArray and userDataArray for 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); 

The account insertion method still returns null. Could not solve the problem so far.

[SOLVED] Mirror API still returns a NULL response, but the account is actually inserted into the Mirror API. The updated code can be found here: http://goo.gl/DVggO6

+1
source share
1 answer

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

Your problem may arise due to the fact that you are going to null for this right now. I would try to fix it and then see if you can see the account on the device.

+1
source

Source: https://habr.com/ru/post/975210/


All Articles