2

下面是我在数据上传程序中使用的代码。

if(isset($_POST['upload'])){
try {
$dailyUploadsFile = $analytics->management_dailyUploads->upload(
$_REQUEST['accountId'],             // your accountID
$_REQUEST['webPropertyId'],         // your web property ID
$_REQUEST['customDataSourceId'],    // your custom data source UID
$_REQUEST['datepicker'],            // date
$_REQUEST['appendNumber'],          // append number
'cost',                             // type of data
array(
  "reset" => $_REQUEST['reset'],
  "data" => file_get_contents_curl($_REQUEST['csvFile']),
  "mimeType" => 'application/octet-stream',
  "uploadType" => 'media'));
} catch (Exception $e) {
die('An error occured: ' . $e->getMessage()."\n");
}
}

这是我点击提交时遇到的错误:

发生错误:调用 POST 时出错https://www.googleapis.com/upload/analytics/v3/management/accounts/34620205/webproperties/UA-34620205-1/customDataSources/P4Zlk69kSCOtVVIu7iFjqw/dailyUploads/2013-03-09/uploads ?appendNumber=1&type=cost&reset=true&uploadType=media&key=AIzaSyDzvHpTNC_CKAnpyfnc1Vjwl_joE5hgBhc : (400) 不支持媒体类型“application/x-www-form-urlencoded”。有效的媒体类型:[application/octet-stream]

请帮忙。

4

1 回答 1

0

Analytics API的dailyUploads 资源已被弃用。建议您使用该uploads 资源

如果您拥有授权的分析服务对象,则以下示例应该适用于 php。

$analytics->management_uploads->uploadData(
    '123456',
    'UA-123456-1',
    '122333444455555',
    array('data' => file_get_contents('example.csv'),
          'mimeType' => 'application/octet-stream',
          'uploadType' => 'media'));
于 2014-12-15T00:41:34.023 回答