获取电子表格的标题 Google 电子表格 api PHP

Get title of Spreadsheet Google Spreadsheet api PHP

我正在尝试获取电子表格名称。但它不起作用。谁能帮帮我吗? 我正在使用 php 和 Google 电子表格和 google 驱动器 api:

function getSheetTitle($spreadsheetID){
    $client = new \Google_Client();
    $client->setApplicationName('Sheets');
    $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
    $client->setAccessType('offline');
    $client->setAuthConfig(GOOGLE_CREDENTIALS);
    
    $client = GoogleClientSheet();
    $service = new Google_Service_Sheets($client);
    
    $worksheetSheets = $service->spreadsheets->get($spreadsheetID);
    return $worksheetSheets->getTitle();
}

只需添加 getProperties()->getTitle()

function getSheetTitle($spreadsheetID){
    $client = new \Google_Client();
    $client->setApplicationName('Sheets');
    $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
    $client->setAccessType('offline');
    $client->setAuthConfig(GOOGLE_CREDENTIALS);
    
    $client = GoogleClientSheet();
    $service = new Google_Service_Sheets($client);
    
    $worksheetSheets = $service->spreadsheets->get($spreadsheetID);
    return $worksheetSheets->getProperties()->getTitle();
}