2017-10-01 4 views
0

Googleドライブにtxtファイルをアップロードするときに問題が発生しています。コードを実行するとすべてがスムーズになりますが、Googleドライブに移動するとアップロードされたものはありません。何かご意見は?GoogleドライブのPython 3にtxtファイルをアップロード

json_key = json.load(open('jsonkey.json') 
scope = ['https://www.googleapis.com/auth/drive'] 
credentials = ServiceAccountCredentials.from_json_keyfile_name('/home/pi/Downloads/jsonkey.json',scope) 

http = httplib2.Http() 
http = credentials.authorize(http) 

drive_service = build('drive', 'v2', http=http) 

media_body1 = MediaFileUpload('sensor1Text.txt', mimetype='text/plain', resumable=True) 
body1 = {'title': 'Sensor1','description': 'A test document', 
     'mimeType': 'text/plain'} 

sensor1File = drive_service.files().insert(body=body1, media_body=media_body1).execute() 
pprint.pprint(sensor1File) 

media_body2 = MediaFileUpload('sensor2Text.txt', mimetype='text/plain', resumable=True) 
body2 = {'title': 'Sensor2','description': 'A test document', 
     'mimeType': 'text/plain'} 

sensor2File = drive_service.files().insert(body=body2, media_body=media_body2).execute() 
pprint.pprint(sensor2File) 

media_bodyCV = MediaFileUpload('cumulativeViewText.txt', mimetype='text/plain', resumable=True) 
bodyCV = {'title': 'CumulativeView','description': 'A test document', 
     'mimeType': 'text/plain'} 

CVFile = drive_service.files().insert(body=bodyCV, media_body=media_bodyCV).execute() 
pprint.pprint(CVFile) 
+0

使用 'を作成' の代わりにご返信用 – hizbul25

答えて

0

利用createの代わりに、[すべてについて] insert

例:

CVFile = drive_service.files().create(body=bodyCV, media_body=media_bodyCV, fields='id').execute() 
+0

おかげで '挿入'。 'AttributeError: 'リソース'オブジェクトに 'create'属性がありません –

+0

'v3'に変更され、スムーズにデバッグされましたが、まだGoogleドライブには何もありません。 –

関連する問題