title: How to get google spread sheet data from Sheet ID (From gid) instead of Spread Sheet Id in php
body: <p>I have one spreadsheet and it contains multiple sheets in tab format .</p>
  
  <p>My code is getting only first spread Sheet data and I have an array which contains all the sheet Id.</p>
  
  <p>My problem is how can I get all the Sheet Data, as I have unique gid for all.</p>
  
  <p>Here SpreadSheet Id is same for all the sheets only sheet id (gid) is different.</p>
  
  <p>I searched a lot, I got only getting data from spreadSheet Id.</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>&lt;?php
  require __DIR__ . '/vendor/autoload.php';
  
  if (php_sapi_name() != 'cli') {
      throw new Exception('This application must be run on the command line.');
  }
  
  /**
   * Returns an authorized API client.
   * @return Google_Client the authorized client object
   */
  function getClient()
  {
      $client = new Google_Client();
      $client-&gt;setApplicationName('Google Sheets API PHP Quickstart');
      $client-&gt;setScopes(Google_Service_Sheets::SPREADSHEETS_READONLY);
      $client-&gt;setAuthConfig('credentials.json');
      $client-&gt;setAccessType('offline');
      $client-&gt;setPrompt('select_account consent');
  
      // Load previously authorized token from a file, if it exists.
      // The file token.json stores the user's access and refresh tokens, and is
      // created automatically when the authorization flow completes for the first
      // time.
      $tokenPath = 'token.json';
      if (file_exists($tokenPath)) {
          $accessToken = json_decode(file_get_contents($tokenPath), true);
          $client-&gt;setAccessToken($accessToken);
      }
  
      // If there is no previous token or it's expired.
      if ($client-&gt;isAccessTokenExpired()) {
          // Refresh the token if possible, else fetch a new one.
          if ($client-&gt;getRefreshToken()) {
              $client-&gt;fetchAccessTokenWithRefreshToken($client-&gt;getRefreshToken());
          } else {
              // Request authorization from the user.
              $authUrl = $client-&gt;createAuthUrl();
              printf("Open the following link in your browser:\n%s\n", $authUrl);
              print 'Enter verification code: ';
              $authCode = trim(fgets(STDIN));
  
              // Exchange authorization code for an access token.
              $accessToken = $client-&gt;fetchAccessTokenWithAuthCode($authCode);
              $client-&gt;setAccessToken($accessToken);
  
              // Check to see if there was an error.
              if (array_key_exists('error', $accessToken)) {
                  throw new Exception(join(', ', $accessToken));
              }
          }
          // Save the token to a file.
          if (!file_exists(dirname($tokenPath))) {
              mkdir(dirname($tokenPath), 0700, true);
          }
          file_put_contents($tokenPath, json_encode($client-&gt;getAccessToken()));
      }
      return $client;
  }
  
  
  // Get the API client and construct the service object.
  $client = getClient();
  $service = new Google_Service_Sheets($client);
  
  
  
  $spreadsheetId = 'xxxxxxx--tttttttttttL_ttthhdfhdhshshshshhshsh-84';///random spread sheet id
  $range = 'A:G';
  $response = $service-&gt;spreadsheets_values-&gt;get($spreadsheetId, $range);
  $values = $response-&gt;getValues();//getting first sheet data only
  
  
      $sheet_id = array();    
      // Load Google API library and set up client
      // You need to know $spreadsheetID (can be seen in the URL)
      $sheetService = $service;  
      $spreadSheet = $sheetService-&gt;spreadsheets-&gt;get($spreadsheetId);
      $sheets = $spreadSheet-&gt;getSheets();
  
      foreach($sheets as $sheet) {
  
      $sheet_id[] = $sheet-&gt;properties-&gt;sheetId;
  
  
      }
  
  
   ///$sheet_id   -- it will give all the id of sheets, I have 36 sheets in a single spreadsheet, so it's giving 36 ids in an array format
  </code></pre>
  
  <p>
  
  <p>Any Suggestion Will be appreciated ..</p>