我有标题等问题。我登录了oauth2并返回了Google错误
“无法读取未定义的属性'spreadsheets'”。我尝试从Google页面复制示例,并且出现相同的错误;
function makeApiCall() {
var spreadsheetBody = {
// TODO: Add desired properties to the request body.
};
var request = gapi.client.sheets.spreadsheets.create({}, spreadsheetBody);
request.then(function(response) {
// TODO: Change code below to process the `response` object:
console.log(response.result);
}, function(reason) {
console.error('error: ' + reason.result.error.message);
});
}
function initClient() {
var SCOPE = 'https://www.googleapis.com/auth/spreadsheets';
gapi.client.init({
'apiKey': 'myke',
'clientId': 'myclientID',
'scope': SCOPE,
// 'discoveryDocs': ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
}).then(function() {
gapi.auth2.getAuthInstance().signIn();
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSignInStatus);
updateSignInStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
});
}
function updateSignInStatus(isSignedIn) {
if (isSignedIn) {
makeApiCall();
}
}
gapi.load('client:auth2', initClient);
答案 0 :(得分:1)
这是因为您已注释掉“发现文档”行。 GAPI需要了解发现文档才能加载正确的API端点。