Skip to content

Instantly share code, notes, and snippets.

@Reldas
Created January 18, 2018 18:53
Show Gist options
  • Save Reldas/78cc8d837494248bb87e72af7180f64b to your computer and use it in GitHub Desktop.
Save Reldas/78cc8d837494248bb87e72af7180f64b to your computer and use it in GitHub Desktop.
Redirect request from Google Home to Google Apps Script and pass back the result
<?php
function http_post($url, $data)
{
$data_url=$data;
$data_len = strlen ($data_url);
return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'POST'
,'header' => "Content-type: application/x-www-form-urlencoded\r\n"
, 'content'=>$data_url
))))
, 'headers'=>$http_response_header
);
return array ('content'=>file_get_contents ($url, false, stream_context_create (array ('http'=>array ('method'=>'POST'
, 'header'=>"Connection: close\r\nContent-Length: $data_len\r\n"
, 'content'=>$data_url
))))
, 'headers'=>$http_response_header
);
}
header('Content-type: application/json');
$post=file_get_contents('php://input');
$data2=http_post('https://script.google.com/macros/s/<<SCRIPTKEY>>/exec',$post);
echo $data2['content'];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment