Fetching HTML content from Google Docs without using the API

I’m trying to use Google Docs as a hosting solution for my website’s HTML files. The goal is to retrieve and show these documents using PHP, but here’s the catch: I don’t want to use the Google Docs API.

I’ve managed to figure out how to get a list of the documents using cURL, which is great. But now I’m stuck on how to actually get the content of those documents.

Is there a way to do this without the API? If so, can anyone point me in the right direction or share some code examples? I’m really hoping to avoid using the official API if possible.

Here’s a basic example of what I’m trying to achieve:

function getGoogleDocContent($docId) {
    // Some magic here to fetch the HTML content without using the Google Docs API
    $html = magicFetchFunction($docId);
    return $html;
}

$content = getGoogleDocContent('abc123xyz');
echo $content;

Any help or suggestions would be much appreciated. Thanks in advance!

While the publish-to-web method works, it’s not ideal if you need real-time updates. Another approach is to use the document’s export link. You can construct it like this: ‘https://docs.google.com/document/d/[DOC_ID]/export?format=html’. Then use cURL to fetch the content:

function getGoogleDocContent($docId) {
    $url = 'https://docs.google.com/document/d/' . $docId . '/export?format=html';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($ch);
    curl_close($ch);
    return $html;
}

This method doesn’t require API access and fetches the latest version of the document. However, be aware that Google may change this unofficial method at any time, so use it cautiously in production environments.

hey, have u tried scraping the google doc directly? u could use something like simple html dom parser in php to grab the content. it’s not foolproof, but might work for basic docs. just remember google might change their html structure anytime, so it’s kinda risky for long-term use. but if ur set on avoiding the API, it could be worth a shot!

I’ve tackled a similar challenge and found that using Google Drive’s publish-to-web feature works more reliably than trying to fetch HTML directly from Google Docs. In Google Docs you can publish your document by going to File, then Share, and selecting Publish to web. After publishing, copy the link provided and in your PHP code use file_get_contents to fetch the HTML content from that link. This method bypasses the need for the API and gives you a clean version of your document, although you must republish whenever you update it.