0

I found a similar article here, but after a lot of testing, I'm still running into issues (Google API Data Transfer Insert: missing resource.applicationDataTransfer).

Essentially I'm trying to transfer ownership of a Google Drive to another person. I got this working for calendars (basically the same code, but different applicationId), but for the Drive, it says it completed without actually moving anything. I have verified that all of the API permissions are correct, and I've even been able to run this successfully in the Google API Explorer (https://developers.google.com/admin-sdk/data-transfer/v1/reference/transfers/insert?authuser=1).

Is there something really simple that I'm missing here?

$service = new Google_Service_DataTransfer($client);  // $client is already defined and working properly

$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';

$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);

$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams($driveTransferParams);
$driveDataTransfer->applicationId = 'idStringForGoogleDriveAndDocs';

$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);

$driveResults = $service->transfers->insert($driveTransfer);

My scopes for the client are: Google_Service_DataTransfer::ADMIN_DATATRANSFER, Google_Service_DataTransfer::ADMIN_DATATRANSFER_READONLY

Thanks in advance!

Ben R.
  • 1
  • 2

1 Answers1

0

Actually, I just figured it out. There were some parameters that needed to be passed within an array, and after doing that, it started working properly. Solution to my problem posted below in case it helps other people.

NOTE 1: see the setApplicationTransferParams line

NOTE 2: see the setApplicationId line

$service = new Google_Service_DataTransfer($client);  // $client is already defined and working properly

$oldUserID = 'oldAccountIdNumberHere';
$newUserID = 'newAccountIdNumberHere';

$driveTransferParams = new Google_Service_DataTransfer_ApplicationTransferParam();
$driveTransferParams->setKey("PRIVACY_LEVEL");
$driveTransferParams->setValue(['SHARED', 'PRIVATE']);

$driveDataTransfer = new Google_Service_DataTransfer_ApplicationDataTransfer();
$driveDataTransfer->setApplicationTransferParams([$driveTransferParams]);
$driveDataTransfer->setApplicationId(['idStringForGoogleDriveAndDocs']);

$driveTransfer = new Google_Service_DataTransfer_DataTransfer();
$driveTransfer->setNewOwnerUserId($newUserID);
$driveTransfer->setOldOwnerUserId($oldUserID);
$driveTransfer->setApplicationDataTransfers([$driveDataTransfer]);

$driveResults = $service->transfers->insert($driveTransfer);
Ben R.
  • 1
  • 2