2012-11-23 6 views
0

SDK를 통해 Google 드라이브에서 문서 목록을 가져 오려고합니다. 서비스 계정을 사용하여 인증을 수행하고 전체 사용 권한이있는 https://www.googleapis.com/auth/drive 범위를 설정합니다.Google 드라이브 API로 파일을 나열 할 수 없습니다.

그러나 Google 드라이브에는 테스트 파일이 있지만 응답에는 빈 항목 목록이 포함되어 있습니다.

 AuthorizationServerDescription desc = GoogleAuthenticationServer.Description; 
     X509Certificate2 key = new X509Certificate2(m_file, "notasecret", X509KeyStorageFlags.Exportable); 

     string scope = Google.Apis.Drive.v2.DriveService.Scopes.Drive.ToString().ToLower(); 
     AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = m_email, Scope = "https://www.googleapis.com/auth/" + scope }; 

     OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState); 


     DriveService service = new DriveService(auth); 

     FilesResource.ListRequest request = service.Files.List(); 
     request.Q = ""; 
     Stream dataStream = request.FetchAsStream(); 
     StreamReader reader = new StreamReader(dataStream); 
     string responseFromServer = reader.ReadToEnd(); 

답변

2

Nivco의 답변에 대한 자세한 내용은 Google Drive SDK: Empty array of files returned from Drive을 확인하십시오.

기본적으로 파일은 서비스 계정의 드라이브에 표시되며 사용자의 파일에는 표시되지 않습니다. 당신이해야 할 것은 설정이 사용자가 가장하려는 도메인의 사용자에 대한 이메일, 그것은을 수행하는 방법에 대한 안내 및 샘플 코드에 대한 Google 드라이브 SDK 설명서를 확인 :

https://developers.google.com/drive/delegation

+0

감사 클라우디오을. 저는이 Google 드라이브 SDK의 초보자입니다. 내가 할 수없는 위임을 설정하려면 특정 도메인의 관리자 여야합니다. Google 드라이브에서 로컬 DB로 내 문서를 다운로드하는 서비스를 설정하고 싶다면 인증을 얻기위한 GUI가 없어야합니다. 어떤 제안? – asir6

+0

앱을 승인하려면 적어도 한 번 이상 OAuth 플로우를 통과해야하지만 새로 고침 토큰을 영원히 저장하고 사용자 상호 작용없이 새로운 액세스 토큰을 생성하는 데 사용할 수 있습니다. https://developers.google.com/drive/about-auth –

+0

감사합니다. 클라우디오. – asir6

관련 문제