簡體   English   中英

GAE上的Google API PHP客戶端庫

[英]Google API PHP Client Library on GAE

我正在嘗試實現一個按鈕,單擊該按鈕會將通用文件上傳到Google雲端硬盤。 以下代碼在我的本地計算機上運行正常(使用Google的SDK用於本地開發),但是當上傳到Google App Engine時,它無法通過slowtest.php中的require_once語句。 這是我的代碼:

HTML文件:

<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>

在這里調用upload():

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();
}

最后,php文件:

<?php

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

如果我刪除'require_once'行,則'success'會添加到網頁上的段落行中。 但是,如果沒有注釋掉,單擊按鈕時沒有任何反應。

頁面上沒有錯誤輸出,但是向控制台輸出了500錯誤。

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

我在命令行上運行相同的代碼,它的工作原理。 如果有人有任何建議,他們將深表感謝。

好的,我發現了問題並且非常簡單。 我指的是google-api-php-client庫作為static_dir,而沒有一個文件是靜態的。

使用 問題的代碼有助於有效地解決此問題:

  
  
  
    -網址 
   :(?)(?)(。*)/谷歌的API的PHP客戶端/ 
   / / 
   
 
 
  
  \n  
 
   
  
  
    腳本:google-api-php-client / \\ 3 / \\ 2 / \\ 1.php 
   

編輯 :請參閱下面的IanGSY評論。 您無需在app.yaml中提及google-api-php-client庫。

有一個詳細的崗位在這里上獲得PHP API客戶端使用App Engine,這是據我所知仍然是准確並且能夠正常運行工作。

我建議按照此博客文章中的說明進行操作,如果仍然無效則報告。

另外,如上所述,絕對不要在app.yaml文件的api客戶端目錄中放置任何路徑。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM