1

I am creating a web-application in which I want to integrate Google Docs using Google Drive. I have made it. Now my next task it append some data to that opened google doc using Drive API. So I want cursor position for that. But i don't know how to find out cursor position using drive API? I searched lot on a google and found solution that I can do that using google APP Script. I am constantly getting this error "DocumentApp is not defined". I am working with Google Drive using Drive API. When I am trying to fetch current opened google doc using

DocumentApp.openById('My-file-Id');

but I am constantly getting this error "documentApp is not defined". Please help me to fix it out or show me the right way to do this.

function printFile(fileId) 
{
    $("#demo_scope").collapse('show');

    var response_data = '<span class="custome_span_text"><center><img src="<?php echo base_url("img/loading.gif");?> "> Wait open the document ...</center></span>';

    $("#google_drive_iframe").show();
    $("#google_drive_iframe").html(response_data);

    var request = gapi.client.drive.files.get({
       'fileId': fileId
    });

    request.execute(function(resp) 
    {
        if(resp.code != 404)
        {
            file = resp;
            var file_id = file.id;

            var some_magic = DocumentApp.openById('My-file-Id');    <!-- Here i am getting error -->

            var file_title = file.title; 
            var file_modifiedDate =  new Date(file.modifiedDate);
            var exportLinks = file.exportLinks;
            var exportLink_html = exportLinks["text/html"];
            $("#google_doc_filenm").val(file_title);
            $("#doc_file_id").val(file_id);
            $("#google_drive_iframe").show(); 
            $("#google_drive_iframe").html('<iframe  src="'+file.alternateLink+'" onclick="checkFocus();"  class="google_iframe"></iframe>');
        }
        else
        {
            $("#google_drive_iframe").html("<center><span class='error_title'><i class='glyphicon glyphicon-remove'></i> Google Document has been not available !</span></center>");
            alertify.error("Please select google document");
            return false;
        }
    });
}
1
  • @Peter, Thanks for your comment, basically i am creating a web-application in which i want to integrate google docs using google drive. I have made it. Now my next task it append some data to that opened google doc using drive API. So i want cursor position for that. But i don't know how to find out cursor position using drive API? I searched lot on a google and found solution that i can do that using google APP Script. but i am getting above error. I think now you can understand. Commented Mar 7, 2016 at 13:34

1 Answer 1

0

The Google Apps Script's Document Service (Class DocumentApp) works as service-side code in a Google Apps Script project. It can't be called directly from a web application's client-side code.

On the other hand, the Google Drive API and the Google Docs API cannot retrieve the cursor position.

Depending on your use case, you might have to change your approach and use Google Apps Script instead of your current web app. With Google Apps Script, you can create dialogs and sidebars that communicate with the open document to get the cursor position.

You might have to start by reading:

  1. https://developers.google.com/apps-script/overview
  2. https://developers.google.com/apps-script/guides/docs
  3. https://developers.google.com/apps-script/guides/dialogs
Sign up to request clarification or add additional context in comments.

Comments

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.