1
我正在使用PHP並希望使用Google Drive REST API(不是版本2)在多張圖片上執行ORC(文本檢測)。如您所知,在版本3中不再有insert
方法,我必須使用create
或copy
來執行ORC。如何在Google Drive REST API(v3)中執行ORC
在這個新版本ORC默認啓用,所以我只是設置orcLanguage,我認爲谷歌沒有任何問題做ORC的圖片,但我的問題是這樣的,我怎樣才能得到ORC行動的輸出?
這裏是我的代碼使用方法:
function GetORC($filename){ require_once 'google-api-php-client-2.0.0-RC7/vendor/autoload.php'; $client = new Google_Client(); $client->setClientId('>my.client.id<'); $client->setClientSecret('>my.client.secret<'); $client->setRedirectUri('>http://the.uri.i.use<'); $client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['accesslic_html/tttest/index.php_token']) && $_SESSION['access_token'])) {
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
} else
$client->setAccessToken($_SESSION['access_token']);
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$file->setTitle(uniqid().'.jpg');
$file->setDescription('A test document');
$file->setMimeType('image/jpeg');
$data = file_get_contents($filename);
$createdFile = $service->files->create($file, array(
'data' => $data,
'mimeType' => 'image/jpeg',
'ocrLanguage' => 'fa',
'uploadType' => 'multipart'
));
var_dump($createdFile);
} else {
$authUrl = $client->createAuthUrl();
header('Location: ' . $authUrl);
exit(); } }