How to fix scripts due to the change in access

There are scripts that need to be fixed due to the change of access in the Google Account Integration feature. This page describes the details of the target script and how to fix them.
*Learn more about the access change in the following announcement.
Yahoo! JAPAN Ads: Yahoo! JAPAN Ads Script change scripts and agreement to new access

Actions that require script content modification

Fix the script that contains the following actions.
Check the fix example.

Actions that will be unavailable after agreement

Read actions for files and folders created outside of Yahoo! JAPAN Ads Scripts on Google Drive.

Functions that will no longer be available:
DriveApp get system processing

DriveApp.getFileById
DriveApp.getFiles
DriveApp.getFilesByName
DriveApp.getFilesByType
DriveApp.getFolderById
DriveApp.getFolders
DriveApp.getFoldersByName
DriveApp.getRootFolderDriveApp.getRootFolder

* The following processes are still available.

  • Read files and folders created by Yahoo! JAPAN Ads Script
  • Creating files and folders directly under My Drive
  • Read, update, and create new spreadsheets directly in My Drive (using SpreadsheetApp)
What to do after fixing

Read and write fixed spreadsheets

Example function:
Working with Spreadsheets with SpreadsheetApp

SpreadsheetApp.create
SpreadsheetApp.openById
SpreadsheetApp.openByUrl

How to determine which scripts need to be fixed

Search for "DriveApp.get" in the script editing screen. If the target function is found, it is subject to fix.
Search shortcuts: [Windows]Ctrl+F, [Mac]Command+F
Target Script
Example search results

Examples of fixing by usage pattern

<Pattern A: Create a file under a specified folder (export report data as CSV)>

What to do before fixing What to do after fixing

■ Actions
Processes data from reports and other documents into csv format strings and creates files under specified folders.

■Script

const folderId = 'Folder ID'; // ID of the folder where we want to store the file
const fileContent = ''; // Generate comma separated string from report data
const fileName = 'test'; const folder = DriveApp.getFolderById(folderId);
const blob = Utilities.newBlob(fileContent, 'text/csv', fileName);
folder.createFile(blob);

Case 1: Change to spreadsheet output
■Script

const spreadsheetId = 'Spreadsheet ID';
const sheetName = 'Sheet1';
const ss = SpreadsheetApp.openById(spreadsheetId);
let sh = ss.getSheetByName(sheetName);
sh.clear();
const reportData = AdsUtilities.getDisplayReport({
  // Define the report you want to get
}).reports[0].rows;
sh.getRange('A1').setValues(reportData);

Reference:

Case 2: Change to file output directly under My Drive
■Script

const fileContent = ''; // Comma separated string
const fileName = 'test';
const blob = Utilities.newBlob(fileContent, 'text/csv', fileName);
const file = DriveApp.createFile(blob);

* By setting DriveApp.createFile instead of createFile for folder, a file will be created directly under My Drive. 

Reference:

<Pattern B: Retrieving csv files (offline conversions or uploading audience lists)>

What to do before fixing What to do after fixing

■ Actions
Get files with a specific name under a specified folder.

■Script

const folderId = 'Folder ID'; // Target Folder ID
const fileName = 'filename'; // target file name
const files = DriveApp.getFolderById(folderId).getFilesByName(fileName);
while (files.hasNext()) {
  const file = files.next();
  const fileData = file.getBlob().getBytes();
  // Action on file
}

■ Actions
Retrieve files with specific file names from across Google Drive.

■Script

const fileName = 'filename'; // target file name
const files =  DriveApp.getFilesByName(fileName);
while (files.hasNext()) {
  const file = files.next();
  const fileData = file.getBlob().getBytes();
  // Action on file
}

■ Actions
Get a file by specifying a specific file ID.

■Script

const fileId = 'fileid'; // target fileid
const file = DriveApp.getFileById(fileId);
const fileData = file.getBlob().getBytes();

* If you are using the retrieved file to perform an automatic upload (Search.OfflineConversionService.upload() or Display.AudienceListService.uploadUserList()).

Prepare a spreadsheet and change its spreadsheet ID to the specified data acquisition.
If you get the list on a regular basis, please update the prepared spreadsheet with the latest information prior to the script periodic run. Then retrieve the contents of the relevant spreadsheet from the script.

When to get a list on a regular basis: offline conversions, uploading an audience list, etc.

Reference:

Offline conversion

Audience list

<Pattern C: Acquisition of image and video files (image and video submission)>

What to do before fixing What to do after fixing
■ Actions
The same action for getting from Google Drive as pattern B

* If you are using the acquired file to perform an automatic upload (such as Display.MediaService.add()).
You will not be able to retrieve images and video files from Google Drive.
Note that the judging of images and videos in Display Ads begins at the time set for the ads. Upload your ad manually when you create it, as uploading it in advance will not be reviewed until it is set to an ad.