0

어떻게이 텍스트 파일을 업데이트 할 때마다 5 초마다 Google 드라이브에 ecg.txt를 업로드 할 수있는 다음 python 코드를 수정할 수 있습니까? 코드는 이제 Oauth가 파일을 업로드 할 때마다 요청합니다. 처음으로 인증을 요청하기를 원합니다.python을 5 초마다 사용하여 Google 드라이브에 텍스트 파일 업로드

#!/usr/bin/python 

import httplib2 
import pprint 

from apiclient.discovery import build 
from apiclient.http import MediaFileUpload 
from oauth2client.client import OAuth2WebServerFlow 


# Copy your credentials from the console 
CLIENT_ID = XXXXXX 
CLIENT_SECRET = XXXXX 

# Check https://developers.google.com/drive/scopes for all available scopes 
OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive' 

# Redirect URI for installed apps 
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' 

# Path to the file to upload 
FILENAME = 'ecg.txt' 

# Run through the OAuth flow and retrieve credentials 
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI) 
authorize_url = flow.step1_get_authorize_url() 
print 'Go to the following link in your browser: ' + authorize_url 
code = raw_input('Enter verification code: ').strip() 
credentials = flow.step2_exchange(code) 

# Create an httplib2.Http object and authorize it with our credentials 
http = httplib2.Http() 
http = credentials.authorize(http) 

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

# Insert a file 
media_body = MediaFileUpload(FILENAME, mimetype='text/plain', resumable=True) 
body = { 
    'title': 'My document', 
    'description': 'A test document', 
    'mimeType': 'text/plain' 
} 

file = drive_service.files().insert(body=body, media_body=media_body).execute() 
pprint.pprint(file) 
+0

XXXX

https://www.youtube.com/watch?v=HoUdWBzUZ-M

. 나는 기존의 열쇠를 죽이고 새 열쇠를 얻을 것이다. – Ryan

답변

0

비디오에서 볼 수 있듯이 당신이 장식을 사용하는 경우 당신을 위해 DB에 액세스 토큰을 저장하고 필요할 때 상쾌한 처리 울부 짖는 소리. 클라이언트 ID와 비밀 밖으로 https://developers.google.com/api-client-library/python/guide/google_app_engine

from oauth2client.appengine import OAuth2Decorator 

decorator = OAuth2Decorator(client_id=CLIENT_ID, 
          client_secret=CLIENT_SECRET, 
          scope=OAUTH_SCOPE, 
          callback_path=REDIRECT_URI) 


class MainPage(webapp2.RequestHandler): 

    @decorator.oauth_required #Simply place this above any function that requires login. 
    def get(self): 
관련 문제