【发布时间】:2018-07-30 14:34:23
【问题描述】:
我正在用 Ruby 编写一段代码,用于使用 Google 数据传输 API 进行数据传输。我的意思是this
我的代码如下:
idOldUser = "116170568974079979335"
idNewUser = "105318746921076261308"
atp = Google::Apis::AdminDatatransferV1::ApplicationTransferParam.new(
key: "PRIVACY_LEVEL",
value: ["PRIVATE", "SHARED"])
appid = 435070579839
adt = Google::Apis::AdminDatatransferV1::ApplicationDataTransfer.new(
application_id: appid,
application_transfer_params: [atp])
dt = Google::Apis::AdminDatatransferV1::DataTransfer.new(
kind: "admin#datatransfer#DataTransfer",
old_owner_user_id: idOldUser,
new_owner_user_id: idNewUser,
application_data_transfers: [adt])
service = Google::Apis::AdminDatatransferV1::DataTransferService.new
service.insert_transfer(dt)
我执行时出现如下错误:
/var/lib/gems/2.4.0/gems/google-api-client-0.23.4/lib/google/apis/core/http_command.rb:212:in `check_status': Unauthorized (Google::Apis::AuthorizationError)
from /var/lib/gems/2.4.0/gems/google-api-client-0.23.4/lib/google/apis/core/api_command.rb:118:in `check_status'
from /var/lib/gems/2.4.0/gems/google-api-client-0.23.4/lib/google/apis/core/http_command.rb:183:in `process_response'
我也尝试从 API Explorer 执行它。以下 JSON 返回 HTTP 200。几分钟后,我在新用户的收件箱中看到一封邮件,说明传输已完成。然后我在日历应用程序中看到一个名为“从用户转移”的条目。但是,它似乎是空的。
{
"oldOwnerUserId": "116170568974079979335",
"newOwnerUserId": "105318746921076261308",
"kind": "admin#datatransfer#DataTransfer",
"applicationDataTransfers": [
{
"applicationId": "435070579839",
"applicationTransferParams": [
{
"key": "PRIVACY_LEVEL",
"value": [
"PRIVATE",
"SHARED"
]
}
]
}
]
}
我用过这个范围:https://www.googleapis.com/auth/admin.datatransfer
奇怪的是,该库的其他方法,例如 list_applications,对我有用。唯一的问题是 insert_transfer 。
您能帮我完成此数据传输吗?如果 Ruby 可以,那就太好了。
提前谢谢你。
【问题讨论】:
标签: ruby google-api google-admin-sdk google-api-ruby-client