How to add Action Url in Firebase push notification - laravel

How to add Action URL in Firebase push notification with Laravel
$firebaseToken = $deviceToken;
$SERVER_API_KEY = env('FCM_SERVER_KEY');
$data = [
"to" => $firebaseToken,
"notification" => [
"title" => $notificationTitle,
"body" => $notificationMessage,
"image" => $companyLogo,
"url" => $actionURL,
]
];
$dataString = json_encode($data);
$headers = [
'Authorization: key=' . $SERVER_API_KEY,
'Content-Type: application/json',
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
$response = curl_exec($ch);
The code is working fine. I am getting push notifications. But my issue is When clicking on push notification it redirects to the Home page of App, not to the Url given

Related

Push notification from Laravel using google firebase

I am trying to send push notification using google firebase , but notification is not coming to phone
public function pushNotificationToUsersTest(){
$apikey = env('FCM_SERVER_KEY');
$deviceToken = array("deviceTocken_1,deviceTocken_2");
$url = 'https://fcm.googleapis.com/fcm/send';
$message = "Message from server";
foreach ($deviceToken as $key => $Token) {
$preview_message = "ACTIONABLE";
$sound = "default";
$fields = array(
'to' => $Token,
'data' => array(
'message' => $message,
'notification_type' => "message_type",
'message_content' => "message_content",
'chat_type' => "chat_type",
'badge' => 10,
'category' => $preview_message,
'sound' => $sound,
)
);
//header with content_type api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$apikey
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
}
print_r($result);
}
When I print Result I am getting like this
{"multicast_id":1610930223174111380,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1657873770379569%73be5013f9fd7ecd"}]}1
When I checked respose code
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
It gives output 400.
Don't know what the issue

How to send notification with image to IOS and android in PHP

I have a Laravel app in which I use some code to send FCM to send notification to IOS and Android, but now I need to include and image in the notification.
the code I am using now is as below
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$notification = [
'body' => 'Message',
'title'=>'title',
'sound' => true,
'priority' => "high",
'vibration'=>true,
'sound'=> "Enabled",
'badge'=>4,
'id'=>2
];
$extraNotificationData = ['one'=>1,'two'=>2];
$fcmNotification = [
//'registration_ids' => json_encode($token,JSON_FORCE_OBJECT), //multple token array
'to' => $this->token, //single token
'data' => $extraNotificationData,
'notification' => $notification
];
$headers = [
'Authorization: key=Server_key',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fcmUrl);
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($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);

Laravel send notification to android using firebase

i am sending notification to android using backend as laravel through firebase but i get error as "append .json to your request URI to use the REST API." Using Postman i am runing this api
This is function which is used to get notification in json in my controller
public function sendNotification(Request $req)
{
$fcmUrl = 'https://playout-52d1f.firebaseio.com';
$token=$req->input('token');
$title=$req->input('title');
$notification = [
'title' => $title,
'sound' => true,
];
$extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
$fcmNotification = [
//'registration_ids' => $tokenList, //multple token array
'to' => $token, //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=AIzaSyDF4_rqij_Bt4zC3GNEVbNFvwX1HHxy5Mo',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
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($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
dd($result );
}

Add Member in List mailchimp api not working [list memeber] cURL: The API key provided is linked to a different datacenter (status:403)

Mailchimp list add member using API Not working
Request:
$apikey = '#####################-us15';
$data = array(
'email_address' => 'test+mailchimp#gmail.com',
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'taiabur rahman'
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://us2.api.mailchimp.com/3.0/lists/6de91c2e1c/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: application/json"));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERPWD, "apikey:" . $apikey);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$response_string = curl_exec($ch);
$curl_info = curl_getinfo($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
echo '<pre>';
print_r($response_string);
die('Mailchimp executed');
Response:
{ "type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title":"Wrong Datacenter",
"status":403,
"detail":"The API key provided is linked to a different datacenter",
"instance":""
}
Hi Change the url to https://us15.api.mailchimp.com/3.0/ on mailchimp documentation
if the last part of your MailChimp API key is us6, all API endpoints
for your account are available at https://us6.api.mailchimp.com/3.0/.
you can read the full documentation here

How do I get the statistics of an app from google play

I want to get the statistics of any particular app from the Google Play. After authentication, I'll provide a URL and the the corresponding stats of that app will start downloading. There is a ZIP folder with CSV files that'll be downloaded.
What I've done is:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = array(
'accountType' => 'GOOGLE',
'Email' => my mail address#gmail.com,
'Passwd' => my password for this account,
'source' => the name of that particular app,
'service' => 'writely'
);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$hasil = curl_exec($ch);
This is for authentication. After this, I want to download the statistics:
$ch = curl_init("https://play.google.com/apps/publish/statistics/download?package=[my apps name]&sd=[starting date]&ed=[ending date]&dim=[dimensional data]&met=[metrics data]&dev_acc=[developer account ID]");
$header[] = 'Authorization: GoogleLogin auth=' . $hasil;
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_exec($ch);
curl_close($ch);
After starting the script, the download should automatically start.

Resources