I'm having some trouble with OCR extraction
The script is supposed to pull a link to an image from a cell in a google sheet and attempts OCR extraction using it, but the generated OCR file keeps getting the google login page instead of the image I need (And I'm logged in...)
Any thoughts on why this could be happening?
As an aside, if I wanted to put the OCR Files into their own folder how would I go about this?
Edit: Shared code
var extract_sheet = spreadsheet.getSheetByName("Extract Data");
var sheet = SpreadsheetApp.setActiveSheet(extract_sheet);
var startRow = 2; // First row of data to process
var numRows = 150; // Number of rows to process
function doExtract() {
var dataRange = sheet.getRange(startRow, 1, numRows, 5)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var file_link = row[4];
var extracted_data = row[6];
var ocr_file_link = row[7];
var valueURL = sheet.getRange(startRow + i, 4).getValue();
var valueURLlength = valueURL.length;
if (valueURLlength != 0) {
var image = UrlFetchApp.fetch(valueURL).getBlob();
var file = {
title: 'OCR File',
mimeType: 'image/png'
};
// OCR is supported for PDF and image formats
file = Drive.Files.insert(file, image, {ocr: true});
var doc = DocumentApp.openByUrl(file.embedLink);
var body = doc.getBody().getText();
//Get link Doc that Generated
sheet.getRange(startRow + Number(i), 6).setValue(file.embedLink);
//Get Content of Doc that Generated
sheet.getRange(startRow + Number(i), 7).setValue(body);
}
}
}
Here's how we solved this issue
Turns out I didn't need to leave google drive at all so I was able to use the Drive File ID instead of a FetchURL.
So I replaced:
var image = UrlFetchApp.fetch(valueURL).getBlob();
with
var image = DriveApp.getFileById(file_ID).getBlob();
And added a var file_ID = row[1]; after var row = data[i];
Hopefully this helps other people who stop by with a similar problem! Thank you.