我必须制作一个 PHP 脚本,它会使用 API 自动将数据上传到 Google Analytics。但是有一个问题:开发人员指南仅针对 python 和 java 编写。PHP 的 Google APIs 客户端库已经有上传方法。请帮我把这个java代码翻译成PHP:
File file = new File("data.csv");
InputStreamContent mediaContent = new InputStreamContent('application/octet-stream', new FileInputStream(file));
mediaContent.setLength(file.length());
Upload upload = analytics.management().dailyUploads().upload("1234",
"UA-1234-1", "123456789", "2012-10-31", 1, "cost", mediaContent);
upload.setReset(true);
DailyUploadAppend append = upload.execute();
或者这个python代码:
media = MediaFileUpload('data.csv', mimetype='application/octet-stream', resumable=False)
daily_upload = analytics.management().dailyUploads().upload(
accountId='1234',
webPropertyId='UA-1234-1',
customDataSourceId='123456789',
date='2012-10-31',
appendNumber=1,
reset=true,
type='cost',
media_body=media).execute()