I'm getting an error, "The requested URL returned error: 401 Unauthorized", when attempting to use PHP cURL with Google Apps Script.
I've been following the following guides, but nothing seems to work:
How do I post to a Google script with cURL in PHP and return text?
Posting data to google apps script using php/curl
I've posted this additional question yesterday which helped me figure out that I needed to get my SSL certificates all setup:
How to use Google Scripts with cURL PHP? [duplicate]
My test.php page:
<div id="body">
<form name="testing" method="post">
Email: <input type="text" name="email"><br>
<input type="submit" value="Submit" onClick="return OnTest1();">
</form>
</div>
<script>
function OnTest1()
{
document.testing.action = "testsubmit.php";
document.testing.submit();
return true;
}
</script>
My testsubmit.php page:
<?php
$url = 'https://script.google.com/a/meditech.com/macros/s/[SCRIPT ID]/exec';
$data['email'] = $_POST['email'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FAILONERROR,true);
$result = curl_exec($ch);
if(curl_error($ch))
{
echo curl_error($ch);
}
else
{
echo $result;
}
curl_close($ch);
?>
And my Google Apps Script:
function doPost(e)
{
return ContentService.createTextOutput(e.parameter.email);
}
I want to be able to at some point pass a bunch of information into my php page to get processed into a database I have setup, from there once it's been dumped into the database I need to then send all that info over to the Google Apps Script to then send out an email.
Thank you to whoever can help.