Google 스프레드 시트에서 Google 슬라이드를 생성하려고합니다. 문제없이 Sheets 스크립트를 사용했지만 Google Slides를 인증하려고 시도하고 Oauth 사용 권한 확인 메시지를 표시 한 후에이 오류가 발생하여 참조를 찾을 수 없습니다. Developers Console에서 Google Slides API 및 Drive API를 사용하도록 설정했습니다.403 오류 메시지 "Google 슬라이드 API가 프로젝트 ... 이전에 사용되지 않았거나 사용 중지되었습니다"
"에 대한 요청이 실패했습니다. 반환 된 코드 403. 서버 응답이 잘림 : {"error ": {"code ": 403,"message ":"Google 슬라이드 API가 프로젝트 ID- ... 전 또는 그것 disab ... (줄 93, 파일 "코드")
오류 코드는 다음과 같습니다. 실패한 함수는 How to download Google Slides as images?에서 복사되었습니다. . 클라이언트 ID 및 암호는 단지 보안을 위해 ommitted, 정의
// from https://mashe.hawksey.info/2015/10/setting-up-oauth2-access-with-google-apps-script-blogger-api-example/
function getService() {
// Create a new service with the given name. The name will be used when
// persisting the authorized token, so ensure it is unique within the
// scope of the property store.
return OAuth2.createService('slidesOauth')
// Set the endpoint URLs, which are the same for all Google services.
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
// Set the client ID and secret, from the Google Developers Console.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
// Set the name of the callback function in the script referenced
// above that should be invoked to complete the OAuth flow.
.setCallbackFunction('authCallback')
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties())
// Set the scopes to request (space-separated for Google services).
// this is blogger read only scope for write access is:
// https://www.googleapis.com/auth/blogger
.setScope('https://www.googleapis.com/auth/blogger.readonly')
// Below are Google-specific OAuth2 parameters.
// Sets the login hint, which will prevent the account chooser screen
// from being shown to users logged in with multiple accounts.
.setParam('login_hint', Session.getActiveUser().getEmail())
// Requests offline access.
.setParam('access_type', 'offline')
// Forces the approval prompt every time. This is useful for testing,
// but not desirable in a production application.
.setParam('approval_prompt', 'force');
}
function authCallback(request) {
var oauthService = getService();
var isAuthorized = oauthService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this tab');
}
}
// from https://stackoverflow.com/questions/31662455/how-to-download-google-slides-as-images/40678925#40678925
function downloadPresentation(id) {
var slideIds = getSlideIds(id);
for (var i = 0, slideId; slideId = slideIds[i]; i++) {
downloadSlide('Slide ' + (i + 1), id, slideId);
}
}
function downloadSlide(name, presentationId, slideId) {
var url = 'https://docs.google.com/presentation/d/' + presentationId +
'/export/png?id=' + presentationId + '&pageid=' + slideId;
var options = {
headers: {
Authorization: 'Bearer ' + getService().getAccessToken()
}
};
var response = UrlFetchApp.fetch(url, options); // This is the failing line 93
var image = response.getAs(MimeType.PNG);
image.setName(name);
DriveApp.createFile(image);
}
API가 올바른 프로젝트 ID에 사용 설정되어 있습니까? 개발자 콘솔의 프로젝트 드롭 다운에서 선택 하시겠습니까? (내가이 오류를 잘못 프로젝트에서 API를 사용하도록 설정하기 전에 언급했기 때문에이 문제를 언급합니다.) – Bardy
예,이 계정의 유일한 프로젝트이며 프로젝트에 API를 사용하는 방법을 파악하는 데 시간이 다소 걸렸습니다. 그러나 제안에 감사드립니다 –