Pushbullet no notification on smartphone using API - php

I created a little app which uses Pushbullet's API.
It is writtent in PhP and uses cURL to proceed the different requests.
At first, I use oauth2 to recieve an access token.
Then it is /v2/pushes/ to send a push to the registred account.
The message is recieved on the Pusbullet account but nothing shows up on the smartphone. There is no notification.
I hope someone can help me.
Thanks.
My function which sends the push:
function send_push($token){
$data = array(
'type' => 'note',
'title' => 'Alert',
'body' => 'My body :)!'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.pushbullet.com/v2/pushes');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer '.$token
));
$data = curl_exec($ch);
curl_close($ch);
}

Related

OneSignal push notification sending to all user instead of one player

I am trying to send push notification to one device by its player_id stored in my database.
but whine it try it keep sending to all users
i don't know what is wrong in my code
$fields = array(
'app_id' => 'XXXXXXXXXXXXXXXXXXXX',
'include_player_ids ' => $player_ids,
'included_segments' => array(
'All'
),
'data' => $data,
'headings' => $title,
'contents' => $content,
'web_buttons' => []
);
$fields = json_encode($fields);
if($player_ids) {
$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 XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
));
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);
just remove 'included_segments' => array('All'),
If you fill both of included_segments and include_player_ids, you will send to all selected player ids and also all selected segments. Segment All mean all subscribers.
you can read about other option on official documentation
I need to remove included_segments and web_buttons
both of them not just included_segments , when I try to just remove included_segments it give me error of {"errors":["You must include which players, segments, or tags you wish to send this notification to."]}
also I don't need 'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'.

Understand api curl instruction

Stuck trying to get an api-connection to work. I believe I don't understand the below example request in the api. Especially the last row "grant_type..etc". How is this line to be handled in CURL? As POSTFIELDS? Get an error {"error":"unsupported_grant_type"}
POST /connect/token HTTP/1.1
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
"grant_type=authorization_code&code=<authorization_code>&redirect_uri=<redirect_uri>"
Code so far:
$ch = curl_init('https://xxxx');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-type: application/x-www-form-urlencoded;charset=UTF-8',
'Authorization: Basic '.base64_encode($clientid.':'.$clientsecret).''
));
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'code' => $_GET['code'],
'redirect_uri' => $redirecturi,
'grant_type' => 'authorization_code'
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
https://auth0.com/docs/applications/reference/grant-types-available
Here all grant type are explained .

JIRA REST API POST call via cURL with OAuth access token returns 401

I have went through steps of getting an access token ( i did this though a terminal using java)
When i try to use a GET request in terminal with java like this:
java -jar rest-oauth-client-1.0.one-jar.jar request ACCESS_TOKEN http://locahost:8015/rest/api/2/issue/TP-113
It works and returns an Issue JSON
But when i try to GET or POST an ISSUE using PHP and cURL like this
$FieldSummary = substr($items[0]->summary,strpos($items[0]->summary,'- ')+2);
$FieldDescription = substr($items[0]->description,0);
$FieldStartTime = new DateTime($items[0]->start->dateTime);
$FieldEndTime = new DateTime($items[0]->end->dateTime);
$dateStart = $FieldStartTime->format("Y-m-d\Th:m:s.sOZ");
$dateEnd = $FieldEndTime->format("Y-m-d\Th:m:s.sOZ");
$url = "http://".$config['jiraAdress']."/rest/api/2/issue/".$FieldKey;
$ch = curl_init($url);
$headers = array(
'Authorization: Bearer ACCESS_TOKEN',
'Accept: application/json',
'Content-Type: application/json'
);
$data = json_encode ( array (
'fields' => array (
'summary' => $FieldSummary,
'description' => $FieldDescription,
'customfield_10007' => $dateStart,
'customfield_10008' => $dateEnd
)
), JSON_PRETTY_PRINT );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
It returns error 401 and error JSON:
{
"errorMessages": [
"You do not have the permission to see the specified issue.",
"Login Required"
],
"errors": {
}
}
What am I doing wrong? Remember that this is JIRA REST API.

Withdraw FCM notification PHP

After sending a FCM notification using PHP a multicast id has been received.
is there any way withdrawing the sent notification using this multicast id?
For instance:
When whatsapp web is open on my pc, the whatsapp notification will be gone from my home screen on my phone after reading it on my pc.
$url = 'https://fcm.googleapis.com/fcm/send';
$notification= array(
'body' => $message,
'priority' => 10,
'sound' => "default"
);
$fields = array(
'to' => $targets,
'notification' => $notification,
'sound' => "default",
'priority' => 10
);
$headers = array (
'Authorization: key='.$gcmKey,
'Content-Type: application/json'
);
$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));
curl_exec($ch);
curl_close($ch);
This is how i 'send' the notification.
My app is being build using phonegap

PHP Curl to form this Post Request

Can someone help me in forming this following POST request in PHP CURL ?
As mentioned in this URL : https://developer.amazon.com/public/apis/experience/cloud-drive/content/nodes
curl -v -X POST --form
'metadata={"name":"testVideo1","kind":"FILE"}' --form
'content=#sample_iTunes.mp4'
'https://content-na.drive.amazonaws.com/cdproxy/nodes?localId=testVideo1&suppress=deduplication'
--header "Authorization: Bearer
Atza|IQEBLjAsAhQ5zx7pKp9PCgCy6T1JkQjHHOEzpwIUQM"
this is what am trying... i want to form the above mentioned type curl request to the amazon server so i can upload a file into it. as there is no examples available am struck in this... can someone helps on this ?
$fields = array(
'multipart' => array(
'name' => 'testupload',
'content' => array(
'kind' => 'FILE',
'name' => 'hi.jpg',
'parents' => $parents
)
)
);
$fields_string = json_encode($fields);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $contenttype);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
You're almost there.
Add this on the curl code.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
This will able to access the url using SSL/HTTPS.

Categories