Google API数据传输插入:缺少resource.applicationDataTransfer [英] Google API Data Transfer Insert: missing resource.applicationDataTransfer

查看:142
本文介绍了Google API数据传输插入:缺少resource.applicationDataTransfer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建简单的PHP脚本,用于在同一域中的用户之间转移驱动器文件的所有权.我想使用管理SDK传输插入方法.

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在此处

我试图通过他们的网页GUI传输数据,但一切正常.我不能做的是如何使其与PHP客户端库一起使用.

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处理服务帐户授权,因此我可以发出这样的请求:

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

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

这将返回域中所有现有传输的数据.基于文档和PHP客户端库的插入操作也应该起作用.

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

执行插入后,我得到代码400,消息为[resource.applicationDataTransfer].

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.

推荐答案

setApplicationDataTransfers方法需要一个Google_Service_DataTransfer_DataTransfer数组,因此您只需要更新以下行(请注意参数中的[])

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

这篇关于Google API数据传输插入:缺少resource.applicationDataTransfer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆