How to remove files from Google Docs API with Zend Gdata library

I’m stuck with a file deletion problem using Google Docs API and Zend Framework 1.11.4

I need to upload documents (word files, PDFs, RTF format) to Google Docs, extract their HTML content, then remove them afterwards. The upload and content extraction work perfectly, but I keep getting errors when trying to delete the files.

Here’s my current approach:

$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
    '[email protected]', 
    'userPassword', 
    Zend_Gdata_Docs::AUTH_SERVICE_NAME
);
$docsService = new Zend_Gdata_Docs($httpClient);

$uploadedDocument = $docsService->uploadFile(
    $documentPath, 
    null, 
    null, 
    Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI
);

$htmlContent = file_get_contents($uploadedDocument->getContent()->getSrc());

$uploadedDocument->delete();

The problem happens at the last line. When I call the delete method, it throws an error saying Expected response code 200, got 409. I’ve been searching for solutions but can’t figure out what’s causing this conflict error.

According to Google’s API documentation, this should be the right way to delete documents. Has anyone encountered this issue before or knows what might be wrong with my code?

The 409 conflict error typically indicates that the document is still being processed by Google’s servers at the time of your delete attempt. There can be a small window of time between when the upload finishes and when the document is fully available for deletion.

I faced a similar issue before. A solution that worked for me was to introduce a short delay before executing the delete method. Consider using sleep(2) or sleep(3) to allow Google’s backend ample time to complete processing.

You could also implement a retry mechanism to handle the 409 error gracefully, attempting deletion again after a brief pause. In my experience, this approach often resolves the issue, especially with larger files, for which a longer wait may be necessary.