0

I'm wasting hours of finding out how to copy a Google Docs (Text document!)..

i tried multiple solutions but none of them worked.

Also the documentId != fileId, which makes the process a bit strange.

The code i've tried so far:

DriveService service = GetDriveService();
DocsService docsService = GetDocsService();
DocumentsResource.GetRequest request = docsService.Documents.Get(fileId);

var GoogleDocument = request.Execute(); //Returns the correct File

FilesResource.GetRequest getFileRequest = service.Files.Get(fileId);

var GoogleFile = getFileRequest.Execute(); //Error - see below

Error:

Google.GoogleApiException: "Not Found"

Inner Exception
JsonReaderException: Error parsing NaN value. Path '', line 1, position 1.

Diese Ausnahme wurde ursprünglich bei dieser Aufrufliste ausgelöst:
    Newtonsoft.Json.JsonTextReader.ParseNumberNaN(Newtonsoft.Json.ReadType, bool)
    Newtonsoft.Json.JsonTextReader.ParseValue()
    Newtonsoft.Json.JsonTextReader.Read()
    Newtonsoft.Json.JsonReader.ReadForType(Newtonsoft.Json.Serialization.JsonContract, bool)
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(Newtonsoft.Json.JsonReader, System.Type, bool)
    Newtonsoft.Json.JsonSerializer.DeserializeInternal(Newtonsoft.Json.JsonReader, System.Type)
    Newtonsoft.Json.JsonConvert.DeserializeObject(string, System.Type, Newtonsoft.Json.JsonSerializerSettings)
    Google.Apis.Services.BaseClientService.DeserializeError(System.Net.Http.HttpResponseMessage)

fileId:

string fileId = "1N9YQSW_n5DAs1uchCz1GTnsIb-CmvhS-KnlsOWok-vs";

What am I missing?

1
  • You haven't added the error you get into your question(please don't post the error as an image, instead edit your question with the error text) Commented Feb 4, 2020 at 15:13

2 Answers 2

1

You are doing a GetRequest instead of a CopyRequest. Also, you only need the Drive API to copy the file. From the documentation and the Quickstart:

var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });
FilesResource.CopyRequest request = service.Files.Copy(fileId);
request.Execute();

Also, the DocumentId is the fileId:

enter image description here Result from doing a Get API Call:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

I was using the Drive.v1 API, which seems not to accept the DocumentId as fileId, but got it working now, Thanks!
0

You should try the online request test by google. And there, you will see if the problem is coming from your code or not... https://developers.google.com/drive/api/v2/reference/files/get?apix=true#try-it When I type your ID, it is not working.

1 Comment

Well it is a file from his Drive, so unless it's completely public it won't work for another user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.