簡體   English   中英

未捕獲的TypeError:無法讀取未定義的屬性“注釋”

[英]Uncaught TypeError: Cannot read property 'comments' of undefined

我正在創建Google Drive Api網站以獲取Google文檔的評論。 每次我發出請求時都會得到:Uncaught TypeError:無法讀取undefined的屬性'comments'。 這是我的代碼:

<Html>
<head>
    <title>test</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
    <script src="https://apis.google.com/js/client.js"></script>
    <script>
        function auth() {
            var config = {
                'client_id': '<YOUR_CLIENT_ID>',
                'scope': 'https://www.googleapis.com/auth/urlshortener'
            };
            gapi.auth.authorize(config, function () {
                console.log('login complete');
                console.log(gapi.auth.getToken());
        });

        retrieveComments();


    }



    function retrieveComments() {

        printComment('<fileid>');
    }
    function printComment(fileId) {
        var request = gapi.client.drive.comments.list({
            'fileId': fileId
        });
        request.execute(function (resp) {
            if (!resp.error) {
                console.log('Modified Date: ' + resp.modifiedDate);


                console.log('Content: ' + resp.content);
            } else {
                console.log('Error code: ' + resp.error.code);
                console.log('Error message: ' + resp.error.message);
                // More error information can be retrieved with resp.error.errors.
            }

        });
    }


</script>



</head>
<body>
    <button onclick="auth();">Authorize</button>
</body>
</Html>    

請幫忙! 我准備拔頭發了。

我發現了代碼的問題。 我授權腳本但從未調用過gapi.client.load('drive','v2',Callback)

<html>
<head>
<title>test</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<script src="https://apis.google.com/js/client.js"></script>
<script>
    function auth() {
        var config = {
            'client_id': '<YOUR_CLIENT_ID>',
            'scope': 'https://www.googleapis.com/auth/urlshortener'
        };
        gapi.auth.authorize(config, function () {
            console.log('login complete');
            console.log(gapi.auth.getToken());
    });

        gapi.client.load('drive', 'v2', retrieveComments());




}

function retrieveComments() {

    printComment('<fileid>');
}
function printComment(fileId) {
    var request = gapi.client.drive.comments.list({
        'fileId': fileId
    });
    request.execute(function (resp) {
        if (!resp.error) {
            console.log('Modified Date: ' + resp.modifiedDate);


            console.log('Content: ' + resp.content);
        } else {
            console.log('Error code: ' + resp.error.code);
            console.log('Error message: ' + resp.error.message);
            // More error information can be retrieved with      resp.error.errors.
        }

    });
}


</script>



</head>
<body>
    <button onclick="auth();">Authorize</button>
</body>
</html>    

現在正在運作!

暫無
暫無

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

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