2017-12-18 4 views
0

내 프로젝트에서 파이썬 스크립트를 확인하고 내 Google 캘린더에 약속을 자동으로 만들었습니다. 먼저 내가 구글 dev에 콘솔 OAUTH의 JSON 파일에서 생성하고 인증하고 내 스크립트를 실행 : 내가 모두 다 내 로컬 컴퓨터에서 실행하지만,구글 API 파이썬 자격 증명 OAUTH 서버 - 서버

SCOPES = 'https://www.googleapis.com/auth/calendar' 
CLIENT_SECRET_FILE = 'client_id.json' 
APPLICATION_NAME = 'Google Calendar API Python Quickstart' 


def get_credentials(): 

home_dir = os.path.expanduser('~') 
credential_dir = os.path.join(home_dir, '.credentials') 
if not os.path.exists(credential_dir): 
    os.makedirs(credential_dir) 
credential_path = os.path.join(credential_dir, 
           'calendar-python-quickstart.json') 

store = Storage(credential_path) 
credentials = store.get() 
if not credentials or credentials.invalid: 
    flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) 
    flow.user_agent = APPLICATION_NAME 
    if flags: 
     credentials = tools.run_flow(flow, store, flags) 
    else: # Needed only for compatibility with Python 2.6 
     credentials = tools.run(flow, store) 
    print('Storing credentials to ' + credential_path) 
return credentials 


credentials = get_credentials() 
http = credentials.authorize(httplib2.Http()) 
service = discovery.build('calendar', 'v3', http=http) 

난 스크립트와 AWS (λ)을 사용하여 모든 종속성을 업로드 할 때 기능 내가 그것을 서버 responde 테스트 할 때 : 나는 인증 방법 저장소와 로컬 시스템에 JSON 자격 증명 파일을 가져 오지 때문입니다 생각하지만, 내가 어떻게 인증 할 수 및 실행 코드 클라이언트 - 대신 서버 서버에서

{ "errorMessage": "module initialization error" }

START RequestId: 2244eefe-e3dd-11e7-a0ce-93ed40a4fa13 Version: $LATEST module initialization error: [Errno 30] Read-only file system: '/home/sbx_user1060'

을 섬기는 사람? 코드의 자격 증명 부분에서

답변

1

사전에

덕분에이 같은 기계에서 기본 자격 증명을 얻기 위해 변경 : 당신의 람다 구성 설정 GOOGLE_APPLICATION_CREDENTIALS에

#import GoogleCredentials 
from oauth2client.client import GoogleCredentials 

credentials = GoogleCredentials.get_application_default() 
service = discovery.build('calendar', 'v3', credentials=credentials) 

를 환경 변수 키로 자격 증명 json 파일 이름을 값으로 사용하십시오.

google api를 사용하는 모든 람다에서 작동합니다.