title: Google Sheets API PHP Curl Script
body: <p>I am trying to access a google sheet by means of the API provided by Google. 
  The following code works by inserting the data. 
  My only problem is that I can not find any appropriate code to get an updated access token with a curl request and It's driving me crazy!</p>
  
  <p>Does anybody have a solution so that the user does not have to enter his login data again and again? 
  Maybe I can store my account data in the code?</p>
  
  <pre><code>$nummer = $_POST['param1'];
  $komm = $_POST['param2'];
  $entnommen = $_POST['param3'];
  $url = 'https://sheets.googleapis.com/v4/spreadsheets/1TDkPMU9EzLwV45V1CrmNU4Xscc3GH9dKc1HDTIzc16k/values/Test!A1:append?includeValuesInResponse=true&amp;insertDataOption=INSERT_ROWS&amp;valueInputOption=RAW';
  $ch = curl_init();
  $data = array("range" =&gt; "Test!A1",
  "majorDimension" =&gt; "ROWS",
  "values" =&gt; array(array($nummer,$komm,$entnommen)));
  $data_string = json_encode($data);
  $headr = array();
  $headr[] = 'Content-type: application/json';
  $headr[] = 'Authorization: Bearer '.$token;
  $headr[] = 'Accept: application/json';
  curl_setopt_array($ch, array(
    CURLOPT_HTTPHEADER =&gt; $headr,
    CURLOPT_RETURNTRANSFER =&gt; 1,
    CURLOPT_URL =&gt; $url,
    CURLOPT_POST =&gt; 1,
    CURLOPT_POSTFIELDS =&gt; $data_string
  ));
  //execute post
  $result = curl_exec($ch);
  $statusCode = curl_getInfo($ch, CURLINFO_RESPONSE_CODE);
  var_dump($result);
  //close connection
  curl_close($ch);
  $character = json_decode($result);
  </code></pre>
  
  <p>Thanks in advance!</p>