2017-01-16 4 views
1

Google 드라이브에 파일을 만드는 Python 프로그램을 작성하려고합니다.OAuth API Google 드라이브 Python

" 
401. That’s an error. 

Error: deleted_client 

The OAuth client was deleted. 

Request Details 
scope=https://www.googleapis.com/auth/drive 
redirect_uri=http://localhost:8080/ 
response_type=code 
client_id=742339009631-b7rv2mnplb22rhdjb1m663aken700cfe.apps.googleusercontent.com 
access_type=offline 
That’s all we know." 

구글이 최신 버전이 있습니까 : 나는 그것을하려고하면, 그것은

'Your browser has been opened to visit: 
() 
    https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&response_type=code&client_id=742339009631-b7rv2mnplb22rhdjb1m663aken700cfe.apps.googleusercontent.com&access_type=offline 
()' 

는 그런 다음 브라우저를 열고 난 다음 얻을라고? 또는 무엇이 문제입니까?

내 코드는 다음과 같습니다 Handling API Errors에서 기반

from pydrive.auth import GoogleAuth 
from pydrive.drive import GoogleDrive 

gauth = GoogleAuth() 
drive = GoogleDrive(gauth) 

f = drive.CreateFile() 
f.SetContentFile('hello.txt') 
f.Upload() 
print('title: %s, mimeType: %s' % (f['title'], f['mimeType'])) 

file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() 

for file1 in file_list: 
    print('title: %s, id: %s' % (file1['title'], file1['id'])) 

답변

1

, error code 401가 잘못된 자격 증명을 나타냅니다. 이 오류는 일반적으로 잘못된 승인 헤더로 인해 발생하거나 사용중인 액세스 토큰이 만료되었거나 유효하지 않습니다.

이러한 오류에 대한 제안 된 조치는 수명이 긴 새로 고침 토큰을 사용하여 액세스 토큰을 새로 고치는 것입니다. 이것이 실패하면 Authorizing Your App with Google Drive에 설명 된대로 OAuth 흐름을 통해 사용자를 안내합니다.

또한 "OAuth 클라이언트가 삭제되었습니다"라는 오류 메시지도 표시되었습니다. 기존 클라이언트 ID가 있는지 확인할 수 있습니다. 그렇지 않은 경우 Google API 콘솔에서 새로운 OAuth 2.0 자격증을 취득해야합니다. 여기에 기본 단계는 Using OAuth 2.0 to Access Google APIs에 있습니다

  1. OAuth를에게 Google API Console에서 2.0 자격 증명을 얻습니다.
  2. Google 인증 서버에서 액세스 토큰을 받으십시오.
  3. API에 액세스 토큰을 보냅니다.
  4. 필요한 경우 액세스 토큰을 새로 고칩니다.

마지막으로, 당신은 또한 Handling errors: revoked or invalid tokens의 모범 사례를 확인 할 수 있으며 Token expiration은 그래서 당신은 더 나은 부여 토큰이 더 이상 작동하지 수있는 가능성을 예상 할 수 있습니다.

희망 하시겠습니까?