0
ヘッダが
$headers = [
'Authorization: key=' . $api_access_key,
'Content-Type: application/json',
];
で、ポストフィールドが
OK応答$fields = [
'registration_ids' => $registrationIds,
'data' => [
'title' => $title,
'message' => $message,
'type' => $type,
],
];
と予想されるなどしている
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
によってがつがつ食うHTTP POSTリクエストをしようとしていますしかし、私がguzzhttpクライアントからこのリクエストを呼び出すと、
$URL='https://android.googleapis.com/gcm/send';
$client = new \GuzzleHttp\Client(['http_errors' => false]);
$response = $client->request('POST', $URL,['form_params'=>$fields],
['headers'=>[
'Authorization' => 'key='.$api_access_key,
'Content-Type' => 'application/json']]);
return $response->getBody()->getContents();
401の権限がないと応答します。私の問題はどこですか?ありがとうございました。