2013-01-11 2 views
1

를 통해 Google 드라이브에 로그인하기 :어떻게 <a href="https://developers.google.com/api-client-library/python/guide/aaa_apikeys" rel="nofollow">documentation</a>에 설명 된대로 내가 할 API 키

#google key 
API_key = "xxxxx" 
#creating an instance of the class 
drive_service = build('drive', 'v2', developerKey = API_key) 
#get a list of child folder in 
children = drive_service.children().list(folderId='yyyyyyy', **param).execute() 

오류 :

An error occurred: https://www.googleapis.com/drive/v2/files/yyyyyyy/children?alt=json&key=xxxxx returned "Login Required">

내가 잘못하고있는 중이 야 무엇을? children 이후

답변

0

OAuth2.0에, 나는 나 자신을 위해 쓴 API_KEY에 사용 여기 예제 프로그램으로 제한 될 것으로 보인다. 이것을 사용하면 폴더를 통해 반복하고 children으로 할 수있는 대부분의 작업을 수행 할 수 있습니다.

import httplib2 
import pprint 
import sys 

from apiclient.discovery import build 

# The API Key of the project. 
API_KEY = '<yourapikey>' 

def createDriveService(): 
    """Builds and returns a Drive service object authorized with the 
    application's service account. 

    Returns: 
     Drive service object. 
    """ 

return build('drive', 'v2', developerKey=API_KEY) 

service = createDriveService() 
def recurse(parent): 
    def recurseFolders(): 
     result = [] 
     page_token = None 
     while True: 
      param = { "q": "'" + parent + "' in parents and mimeType = 'application/vnd.google-apps.folder'" } 
      if page_token: 
       param['pageToken'] = page_token 
      files = service.files().list(**param).execute() 
      result.extend(files['items']) 
      page_token = files.get('nextPageToken') 
      if not page_token: 
       break 

     for folder in result: 
      recurse(folder.get("id")) 

    def printChildren(): 
     result = [] 
     page_token = None 
     while True: 
      param = { "q": "'" + parent + "' in parents and mimeType != 'application/vnd.google-apps.folder'" } 
      if page_token: 
      param['pageToken'] = page_token 
      files = service.files().list(**param).execute() 
      result.extend(files['items']) 
      page_token = files.get('nextPageToken') 
      if not page_token: 
       break 

     for afile in result: 
      # Cannot use webViewLink, because it's only valid for static html content 
      print afile.get('title') + u':' + u'"' + afile.get("webContentLink") + u',"' 

    recurseFolders(); 
    printChildren(); 
recurse('<folder_id>') 
관련 문제