Google API Data Transfer Insert: missing resource.applicationDataTransfer

六眼飞鱼酱① 提交于 2019-12-11 07:28:53

问题


I'm creating simple PHP script for transfering ownerships of drive files between users in the same domain. I want to use Admin SDK Transfers and Insert method.

Google has documentation about transfers here

I tried to transfer data through their webpage GUI and it went fine. What I can't do is how to make it work with PHP Client library.

Let's say I have prepared object for creating requests to Transfers resource

$transfers = new \Google_Service_DataTransfer($googleConnection);

googleConnection handles service account authorization so i can make requests like this:

$data = $this->transfers->transfers->listTransfers();

This returns data of all existing transfers in domain. Based on documentation and PHP Client library insert operation should work also.

$transferParams = new \Google_Service_DataTransfer_ApplicationTransferParam();
    $transferParams->setKey("PRIVACY_LEVEL"); //what kind of docs I want to transfer
    $transferParams->setValue(['SHARED', 'PRIVATE']);

    $appDataTransfer = new \Google_Service_DataTransfer_ApplicationDataTransfer();
    $appDataTransfer->setApplicationTransferParams($transferParams);

    $appDataTransfer->applicationId = "iDString";    //set application ID

    $newTransfer = New \Google_Service_DataTransfer_DataTransfer();

    $newTransfer->setOldOwnerUserId('accountID'); //origin account IDs are placeholders
    $newTransfer->setNewOwnerUserId('account2ID'); //destination account
    $newTransfer->setApplicationDataTransfers($appDataTransfer);

    $result = $this->transfers->transfers->insert($newTransfer); //execute insert

After executing insert I am getting code 400 with message Missing required field: [resource.applicationDataTransfer].

If I test real parameters via web they work. I must be missing something, because that exception doesn't make sense at all.

I'm also open to alternative solutions.


回答1:


setApplicationDataTransfers method expects an array of Google_Service_DataTransfer_DataTransfer so you just need to update the following line (note the [] in the params)

$newTransfer->setApplicationDataTransfers([$appDataTransfer]);


来源:https://stackoverflow.com/questions/45268548/google-api-data-transfer-insert-missing-resource-applicationdatatransfer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!