Colin King
Colin King

Reputation: 83

Google API PHP Client Library on GAE

I'm trying to implement a button, that when clicked, will upload a generic file to Google drive. The following code works fine on my local machine (using Google's SDK for local dev), but when uploaded to Google App Engine it can't get past the require_once statement in slowtest.php. Here is my code:

HTML file:

<head>
    ...
    <script src="js/data.js"></script>
    ...
</head>

<body>
    <div class="container">

        <h2>Data Page</h2>
        <p>Press the button to upload a file.</p>

        <button onclick="upload()" style="margin-bottom: 5px;">Upload</button>

        <p>Return: <span id="uploadedFiles"></span></p>
    </div>
</body>

Calls upload() here:

function upload() {
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById("uploadedFiles").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", "slowtest.php", true);
    xmlhttp.send();
}

And finally, the php file:

<?php

require_once 'google-api-php-client/src/Google_Client.php';
echo 'success!';
?>

If I remove the 'require_once' line, 'success' is added to the paragraph line on the webpage. However, when it isn't commented out, nothing happens when the button is clicked.

There is no error output on the page, but a 500 error is outputted to the console.

Failed to load resource: the server responded with a status of 500 (Internal Server Error) 

I've run the same code on the command line and it works. If anyone has any suggestions, they would be deeply appreciated.

Upvotes: 0

Views: 396

Answers (2)

Stuart Langley
Stuart Langley

Reputation: 7054

There is a detailed post here on getting the PHP API client working with App Engine, which as far as I know is still accurate and works correctly.

I would suggest following the instructions in this blog post and report back if it still does not work.

Also, definitely do not put any paths in the api client directory in your app.yaml file, as mentioned above.

Upvotes: 1

Colin King
Colin King

Reputation: 83

Okay, I found the problem and it is pretty simple. I was referring to the google-api-php-client library as a static_dir, when instead none of the files are static.

Using the code from this question helped efficiently solve this:

- url: /google-api-php-client/(.?)/(.?)/(.*)
  script: google-api-php-client/\3/\2/\1.php

EDIT: See the comment by IanGSY below. You don't need to mention the google-api-php-client library at all in your app.yaml.

Upvotes: 1

Related Questions