Uncaught TypeError: Cannot read property 'comments' of undefined
Uncaught TypeError: Cannot read property 'comments' of undefined
我正在创建一个 Google Drive Api 站点以从 Google 文档中获取评论。每次我发出请求时,我都会得到:Uncaught TypeError: Cannot read 属性 'comments' of undefined。这是我的代码:
<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>
现在可以使用了!
我正在创建一个 Google Drive Api 站点以从 Google 文档中获取评论。每次我发出请求时,我都会得到:Uncaught TypeError: Cannot read 属性 'comments' of undefined。这是我的代码:
<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>
现在可以使用了!