I created a php file to send an example notification to my devices:
<?php
$ch = curl_init();
$url = "https://api.usergrid.com/ratnhanhgon/thd/devices/*/notifications";
$send = "payload=exam:hello";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $send);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$out = curl_exec ($ch);
echo $out;
?>
But when I run it, i received this error message:
{"error":"web_application","timestamp":1417235590486,"duration":0,"exception":"javax.ws.rs.WebApplicationException"}
May you explain where was I wrong? Did I miss something?
Are you actually calling it with the asterisk in there? You need to provide a device uuid there.
Also, it consumes JSON, so you'll need to POST a JSON object to the /notifications endpoint. Something like:
$payload = array(
"payloads" => array(
"apple" => array(
"aps" => array(
"alert":"Your message here."
)
)
)
);
$send = json_encode($payload);
Related
Ok so my work wants one of our websites to pull posts from another one of our wordpress website.
I found this endpoint and when I throw it in a browser or in post man I get the data no problem.
However when I do a basic curl request from my external website and echo the results it shows a blank page. The request is a 200 ok but no data showing?
$curl = curl_init();
curl_setopt_array($curl, array
(
CURLOPT_URL => 'https://www.hidden.com/wp-json/wp/v2/posts',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('title' => 'Sample Post','status' => 'publish'),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
I thought maybe I needed to be on https since this was on the local server but when pushed to secure dev server same issue.
Then I thought maybe I need to authenticate so I tried this:
$username='hiddenusr';
$password='hiddenpass';
$URL='https://www.hidden.com/wp-json/wp/v2/posts';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
echo $result;
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
curl_close ($ch);
still nothing? What am I doing wrong? and why work in postman but not on my site?
I'm sending firebase notification with PHP, but the message isn't sent. The notification seems to have been sent, but it does not. I tried again with POSTMAN and reached the same result. I want to send notifications to all users.
<?php
define('API_ACCESS_KEY','xxxxxxxxxxxxxxxxxxxxxxx');
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$notification = [
'title' =>'TITLE',
'body' => 'MESSAGE.'
];
$extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
$fcmNotification = [
'to' => "/topics/all",
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=' . API_ACCESS_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);
echo $result;
?>
Returned data
{"message_id":4709853598141003946}
Make sure your variables are correct and the topic is case sensitive, I capitalized my "A" in "all" and it worked just fine for me.
I am currently using OneSignal as the web-push provider, and would like to independently send a message to all of my users without depending and relying on their service (and obviously, the newly introduced costs).
OneSignal do let me download my entire user database including the GCM/FCM data.
Is the data provided sufficient to write a simple code that sends a message to a user from the database?
Here is an example of one row, with the fields they provide:
id
identifier
session_count
language
timezone
game_version
device_os
device_type
device_model
ad_id tags
last_active
playtime
amount_spent
created_at
invalid_identifier
badge_count
lat
lon
rooted
ip
country web_auth
web_p256
7a2ad79c-4315-4b57-be2b-6cce179260ed
https://android.googleapis.com/gcm/send/eNKyRHWMfMs:APA91bHMRVQk7gz27_JNTEsMnorqzd_JR6626eg43p-BhXmb1pslLX66db6w5-Aj--3GtpoCSVRHzMv2y_9tQlIVWKLakfmfLEAXy3rOsI4dvujHwou_X2wY9-TezBuDgST-o5A0fvo3
1
en
28800
56.0
5
Win32 Chrome
{}
2017-03-11 13:48:03.503015
0
0.00
2017-03-11 13:48:03.488008
t
0
f
125.60.243.173
PH
BFgB3OnEz3fGbNEbC/hiMA==
BMgmk8uppenwp1c5sPprEPHNYOu7n8yUjbAU7sKaImqldN+WnJosdZmUV/d4bv7RyQYiqu/z6KsJSn99B+A3IIA=
If it is possible, I would immensely appreciate being sent in a direction of a code example, in any language (preferably PHP, not necessarily), that could accomplish sending a message to this user as an example.
Thank you!
You can send the notification to user using rest api of one signal .
Send a curl request on one signal with all details required -
$content = array(
"en" => '' // Your message content
);
$heading = array(
"en" => '' // Put heading according to you
);
$fields = array(
'app_id' => , // Enter our app id here
'filters' => array( array( "field" => "tag", "key" => "ad_id", "relation" => "=", "value" => 0) ), // You can use the ad_id data tag
"url" => '', // Enter your landing url
'contents' => $content,
'headings' => $heading
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic '.REST_API_KEY.'' // Your api key
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
You can use data tag or plaer id in the realtion to send notification to filtered user.
I have no idea how to implement this plugin.
My idea is, how to implement one signal plugin(in wordpress) could send push notification via location to my android studio app users.
I want to group my app users via location so that only in that area can receive notification.
Is there any best idea to configure onesignal plugin?
Please Read The api documentation for one signal post push notification.
first you need to create segment fro your backend of the one signal then use below code for send push notification.
<?PHP
function sendMessage(){
$content = array(
"en" => 'Your Push notification message'
);
$fields = array(
'app_id' => "------------- Your App Id ----------",
'included_segments' => array('Your Segment Name'),
'data' => array("foo" => "bar"),
'contents' => $content
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
?>
After reading this doc: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#enhancedecom
I'm trying to send data to google analytics like this :
$data = array(
"v" => 1,
"tid" => "XX-xxxxx-x",
"cid" => "999",
"t" => "pageview",
"dh" => "mydemo.com",
"dp" => "/receipt10",
"dt" => "Receipt%20Page10",
"ti" => "T12367",
"ta" => "Google%20Store%20-%20Online",
"tr" => 40.39,
"tt" => 2.85,
"ts" => 5.34,
"pa"=>"purshase",
"tcc" => "SUMMER2013",
"pr1id" => "P1265445",
"pr1nm" => "Android%20Warhol%20T-Shirt 2",
"pr1ca" => "Apparel",
"pr1br" => "Google",
"pr1va" => "Black",
"pr1ps" => 2);
$content = http_build_query($data);
$content = utf8_encode($content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssl.google-analytics.com/collect");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, utf8_encode($content));
//curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
It's partialy working : i've got a hit in the real time view, and i can see the page in the "all page" view, but nothing in the ecommerce view.
what i'm missing?
You will need to wait. It takes 24 - 48 hours for the data to show up in the standard reports. Its still being processed.
If its working in realtime then you will probably see it tomorrow under ecommerce.
Not sure if you've already caught this but you have a typo in the attribute "purchase" written in your example as "pa"=>"purshase"
It's possible the other attribute won't be picked up without this event properly described.