0

I am trying to download a file from google drive using C# .net. I am using the example code from https://developers.google.com/drive/web/manage-downloads

The code does not compile and giving definition error for IAuthenticator

error CS0234: The type or namespace name 'Authentication' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'IAuthenticator' could not be found (are you missing a using directive or an assembly reference?)

using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Authentication;

public static System.IO.Stream DownloadFile(
  IAuthenticator authenticator, File file) {

I also tried

service.Files.Get(fileId).Download(myFileStream); 

However this is giving error on "file already used by process"

Has anyone successfully used the C# example to download file?

PS: I have installed required nuget pacakages

PM> install-package Google.Apis.Auth
Attempting to resolve dependency 'Google.Apis.Core (≥ 1.9.0)'.
Attempting to resolve dependency 'Microsoft.Bcl (≥ 1.1.9)'.
Attempting to resolve dependency 'Microsoft.Bcl.Build (≥ 1.0.14)'.
Attempting to resolve dependency 'Microsoft.Bcl.Async (≥ 1.0.168)'.
Attempting to resolve dependency 'Microsoft.Net.Http (≥ 2.2.22)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Google.Apis.Auth 1.9.0' already installed.
GoogleDrive already has a reference to 'Google.Apis.Auth 1.9.0'.
Kara
  • 6,115
  • 16
  • 50
  • 57
Henry
  • 81
  • 6
  • can you please show us what exactly you have? what all the namespaces you have included? did u use namespace for Authenication? OAuth? – Deepak Sharma Nov 13 '14 at 04:22
  • Here is what I have: using Google.Apis.Auth.OAuth2; using Google.Apis.Download; using Google.Apis.Drive.v2; using Google.Apis.Drive.v2.Data; using Google.Apis.Services; – Henry Nov 13 '14 at 05:45
  • at which line u r getting this error. Can you please paste the whole Exception details. including line number and stack trace.. – Deepak Sharma Nov 13 '14 at 06:00
  • added details in original question. – Henry Nov 13 '14 at 06:56
  • 1
    in actually you dont have this `Interface` in updated version check the Obsolete comment in [given link](https://code.google.com/p/google-api-dotnet-client/source/browse/Src/GoogleApis/Apis/Authentication/IAuthenticator.cs?r=e6585033994bfb3a24d4c140db834cb14b9738b2).. this code will not work for latest dll.. you have to use the equivalent classes.. check one sample here http://stackoverflow.com/questions/23883379/where-can-i-find-serviceaccountcredential – Deepak Sharma Nov 13 '14 at 07:31

1 Answers1

0

IAuthenticator authenticator Used For SDK.There is not much detail on IAuthenticator in google Api But You can Use for API

        fileID="asd383d8ied2edj82dnc0v";
        Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Execute();
        return  service.HttpClient.GetStreamAsync(file.DownloadUrl).Result;