Telary Telary - 1 year ago 88
Javascript Question

How to get the name of the Google doc only with js?

I have a link to the google doc in this format:

When I post it in slack or skype, these programs display me the real name of this doc:

enter image description here

enter image description here

I need to display "Test document" name on my site. Is it possible to do it only with javascript? Without creating any services on the server?

Thank you for your help!

Answer Source

You need to use the get method of the Google Drive's API which takes one required field which is the fileId which will be 15vISe8Lw841LqdVRtZM3egniCeRcsPXtivqxuh76t6o in your case,

To retrieve your file metadata programatically, Try this,

function printFile(fileId) {
  var request ={
    'fileId': fileId
  request.execute(function(resp) {
    console.log('Title: ' + resp.title);
    console.log('Description: ' + resp.description);
    console.log('MIME type: ' + resp.mimeType);

I have tried with your document ID, and here is the output which I had received upon a successful response,

enter image description here

So you can use the title attribute to print your document tile in your site.

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download