Created
January 18, 2018 18:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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