J'ai reçu l'obligation d'envoyer des e-mails rédigés (Gmail) à l'heure prévue. J'ai essayé le code ci-dessous.API Gmail PHP Client Library ou api - Comment envoyer un brouillon gmail?
$access_token = 'ya29.DxswidlwadllsidVeg5B67CdpLN6QR0d1nCuQmg9GaMT9iq8-zIA8O29yR9rEMM';
//the access token is subject to change every hour
$header = array('Content-Type: message/rfc822', "Authorization: Bearer $access_token");
$to = '125699645855239833'; // this is a draft id.
$line = "\r\n";
$raw='';
$url = 'https://www.googleapis.com/upload/gmail/v1/users/me/drafts?fields=id&key=XsqwwosqldwwdssaOLwotWD6seRloXZM';
$raw .= "id: $to ".$line.$line;
$method_type = 1; // set as post method
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
if($header !== 0){
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
}
if($method_type == 1 or $method_type == 0){
curl_setopt($curl, CURLOPT_POST, $method_type);
}else{
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
}
if($data !== 0){
curl_setopt($curl, CURLOPT_POSTFIELDS, $raw);
}
$response = curl_exec($curl);
$json = json_decode($response, true);
print_r($json);
curl_close($curl);
J'ai obtenu résultat après affichage boucle comme ci-dessous
Array ([id] => r-5083530165761240787), mais le projet (e-mail) n'a pas été défini.
Cela fonctionne pour moi. :) –