2016-09-16 1 views
2

API를 사용하여 Google 웹 로그 분석에 CSV를 업로드해야합니다. 모든 것이 정상적으로 처리되지만 열의 파일 이름에 "알 수없는 파일 이름"이 표시됩니다.uploadData의 파일 이름

$analytics = new \Google_Service_Analytics($client); 
try { 
    $analytics->management_uploads->uploadData(
     '<acc id>', 
     'UA-xxx', 
     'xxxxxxxxxxxxxx', 
     array(
      'data' => file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/ex.csv'), 
      'mimeType' => 'application/octet-stream', 
      'uploadType' => 'media' 
     ) 
    ); 

} catch (apiServiceException $e) { 
    print 'There was an Analytics API service error ' 
     . $e->getCode() . ':' . $e->getMessage(); 

} catch (apiException $e) { 
    print 'There was a general API error ' 
     . $e->getCode() . ':' . $e->getMessage(); 
} 

이 flename와 파일을 게시 할 수 있습니다 : 여기

File name is unknown

내 코드? 고맙습니다!

+1

나는 최근에 같은 질문을했으며 현재 API를 통해 파일 이름을 추가 할 수 없다는 사실을 발견했습니다. –

답변

0

클라이언트 라이브러리와 Google 애널리틱스 API에 문제가있는 것처럼 보입니다. POST 본문 정보

Management API Cost Data Upload .csv Doesn't Have Filename

에서 파일 이름을 제거 클라이언트 라이브러리의

결과는 당신은 클라이언트 라이브러리를 사용하지 않음으로써 그 주위를 얻을 수 있습니다.

import pycurl 
import json 

def curlUpload(accountId, webPropertyId, customDataSourceId, csv): 
     credential_path = 'PATHTOYOURCREDENTIALSJSONFILE' 
     f = open(credential_path) 
     googleAccessToken = json.loads(f.read())['access_token'] 

     c = pycurl.Curl() 
     c.setopt(c.URL, 'https://www.googleapis.com/upload/analytics/v3/management/accounts/' + accountId + '/webproperties/' + webPropertyId + '/customDataSources/' + customDataSourceId + '/uploads?access_token=' + googleAccessToken) 
     c.setopt(c.HTTPPOST, [ 
     ('fileupload', (
       c.FORM_FILE, csv, 
       c.FORM_CONTENTTYPE, 'application/octet-stream' 
     )), 
     ]) 
     c.perform() 
     c.close()