我正在使用:
$result = $analytics->management_uploads->uploadData(self::$accountId, self::$webPropertyId, $dataSourceId, array(
"data" => $dataCsv,
"mimeType" => 'application/octet-stream',
"uploadType" => 'media')
);
其中$ dataCsv是内容csv文件。
如何指定文件名?
答案 0 :(得分:0)
Google API似乎不支持分配文件名。但是,如果您想通过API管理上传,则可以存储(或列出)上传内容的ID。例如:
public class Foo implements EntryPoint {
public static interface MyInterface {
}
public static class MyObject implements MyInterface {
}
public void onModuleLoad() {
MyInterface myObject = new MyObject();
List<MyInterface> myList = Arrays.asList(myObject);
}
}
使用id,您可以删除之前的上传内容,例如:
/**
* Upload data to Google Analytics property in dataset
*
* @param string $accountId
* @param string $webPropertyId
* @param string $customDataSourceId
* @param string $uploadCSV
*
* @return integer upload ID
*/
public function upload($accountId, $webPropertyId, $customDataSourceId, $uploadCSV, $prev_upload_id = null) {
$result = $this->getAnalyticsService()->management_uploads->uploadData(
$accountId,
$webPropertyId,
$customDataSourceId,
[
'data' => $uploadCSV,
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'
] );
$this->last_upload_status = $result['status'];
return $result['id'];
}