Firebase Api Key is not working for iOS only - php

I want to send push notification using firebase in php. My code is working fine for android but not working for ios device.
And I am getting success:1 for both cases.
Here is my code
<?php
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array('registration_ids' => $token,
'data' => array('title'=>'Title',
'body'=>$message['message'],
'image'=>$imagepath,
'priority'=>'high'
)
);
$headers = array(
'Authorization:key=AIzaSyBiOCXbU7roG59_**********vWa4Xc' ,
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
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);
return $result;
?>
And response is
stdClass Object
(
[multicast_id] => 8.5168949472892E+18
[success] => 1
[failure] => 0
[canonical_ids] => 0
[results] => Array
(
[0] => stdClass Object
(
[message_id] => 0:1493801065120413%2d69fd2bf9fd7ecd
)
)
)

Delete app from iphone and install again, After that you will get new firebase token try to send push again.
Debug this first from php side they are sending push on newer device token.

Related

VirusTotal Api unclear usage

I scan files from folder ($cfile has fake content intentionally)
$api_key = getenv('VT_API_KEY') ? getenv('VT_API_KEY') :$this->_key;
$cfile = 'asdasdas';
$post = array('apikey' => $api_key,'file'=> $cfile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.virustotal.com/vtapi/v2/file/scan');
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // remove this if your not debugging
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); // please compress data
curl_setopt($ch, CURLOPT_USERAGENT, "gzip, My php curl client");
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,True);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
And get fine result with something like :
stdClass Object
(
[scan_id] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec-1573916013
[sha1] => d8cc708a1760020e00e1da0e83dc1f7b25e5a5ab
[resource] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec
[response_code] => 1
[sha256] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec
[permalink] => https://www.virustotal.com/file/ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec/analysis/1573916013/
[md5] => 7ae6fa4e9595a6e9d7987b4cd66f5b7f
[verbose_msg] => Scan request successfully queued, come back later for the report
)
Why do I set file wrong and have good result ?

Push notification not sending from PHP api

I have written an API in PHP which will receive Firebase token and will send push notification to Android device.
I have tested Android side code and it receiving sample notification from Firebase console using token. But when I am trying to send from PHP api then it's not sending notification.
Here is my php API.
// send firebase push notifcaiton
$url = 'https://fcm.googleapis.com/fcm/send';
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$fields = array (
'registration_ids' => array (
$pnsToken
),
'data' => array (
"message" => $message,
"guestId" => $guestId,
"guestEntryId" => $guestEntryId,
"guestName" => $guestName,
"guestAddress" => $guestAddress,
"reason" => $reason
)
);
//header includes Content type and api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$api_key
);
$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);
if ($result === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
I don't know why it's not sending push notification from PHP api.
Edit
Here is fcm error which I am receiving :
"fcmResult": "{\"multicast_id\":7084003691931660410,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"NotRegistered\"}]}",

How t transfer money paypal to payment?

I am new in paypal API. I am trying to transfer money from one paypal account to another paypal account but I am getting error. so please check my code and tell me what is wrong error.Your suggestions are welcome.
This is the code I am trying :
$receiverList=array();
$receiverList["receiver"][$counter]["amount"]=50;
$receiverList["receiver"][$counter]["email"]='amandeep.singh########.com';
$receiverList["receiver"][$counter]["paymentType"]="PAY";
$receiverList["receiver"][$counter]["invoiceId"]=1548569;
$payLoad["actionType"]="PAY";
$payLoad["cancelUrl"]="";
$payLoad["currencyCode"]="EUR";
$payLoad["receiverList"]=$receiverList;
$payLoad["feesPayer"]="SENDER ";
$payLoad["sender"]["email"]='amandeep.singh########.com';
//run the call
$API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
$payLoad["requestEnvelope"]= array("errorLanguage"=>urlencode("en_US"),"detailLevel"=>urlencode("ReturnAll"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-PAYPAL-REQUEST-DATA-FORMAT: JSON',
'X-PAYPAL-RESPONSE-DATA-FORMAT: JSON',
'X-PAYPAL-SECURITY-USERID: amandeep.singh-facilitator_api1.mobilyte.com',
'X-PAYPAL-SECURITY-PASSWORD: AZVMY9FZK2J#####',
'X-PAYPAL-SECURITY-SIGNATURE: AFcWxV21C7fd0v3bYYYRCpSSRl31AodeBybN3aK381NetHgWkUW1####',
'X-PAYPAL-APPLICATION-ID: APP-80W28##########3'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payLoad));
$response = curl_exec($ch);
$response = json_decode($response, 1);
after call above curl, paypal return this error:-
Array ( [responseEnvelope] => Array ( [timestamp] => 2016-02-21T21:58:24.854-08:00 [ack] => Failure [correlationId] => 3693e36af347f [build] => 20367699 ) [error] => Array ( [0] => Array ( [errorId] => 560022 [domain] => PLATFORM [subdomain] => Application [severity] => Error [category] => Application [message] => The X-PAYPAL-APPLICATION-ID header contains an invalid value [parameter] => Array ( [0] => X-PAYPAL-APPLICATION-ID ) ) ) )
The APPID for the sand-box and live are different to one another.
The Sand box should be used with the following ID :
APP-80W284485P519543T
And the live is used with the ID which is similar to that of APP credentials.

LMS API account creation resulting in an error

I am working on Canvas LMS and have access token. I need to create an user account using web service in PHP. I have tried to do it using CURL (post method) but getting an error in response. However GET is working fine.
Like if I need to get information about course etc, it's working fine but account creation not working using CURL (post). Below is my code.
$url = "https://xxxxx.com/api/v1/accounts/2/users";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' .$token ) );
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
'name' => 'vaue',
'short_name' => 'value',
'unique_id' => '1121',
));
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
curl_close($curl);
Error:
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[message] => An error occurred.
[error_code] => internal_server_error
)
)
[error_report_id] => 1124
)
I resolved my issue. The reason of "internal server error" was not sending required fields. Here are the required fields if someone need to know.
'user[name]' => '',
'user[terms_of_use]' => 'true',
'pseudonym[unique_id]' => '',//i.e valid email
'pseudonym[send_confirmation]'=>'true'
Now my CURL request is working fine and I am able to create an account successfully.
It looks like the keys for your arguments are incorrect. They should be:
'user[name]' => 'vaue',
'user[short_name]' => 'value',
'pseudonym[unique_id]' => '1121',
You can find the docs for your canvas install at: "https://{your canvas domain}/doc/api/index.html" or if you are using cloud hosted canvas at "api.instructure.com"

Goo.gl URL Shortener Stopped Working (php/curl)

For some reason my script stopped working today. When I look in the API control panel says I still have 100% left of usage. Any ideas? Did they change the auth way?
function url_small($url)
{
//This is the URL you want to shorten
$longUrl = $url;
$apiKey = '#####HIDDEN######';
//Get API key from : http://code.google.com/apis/console/
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
//change the response json string to object
$json = json_decode($response);
curl_close($curlObj);
return $json->id;
}
Response
stdClass Object
(
[error] => stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[domain] => usageLimits
[reason] => dailyLimitExceededUnreg
[message] => Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.
[extendedHelp] => https://code.google.com/apis/console
)
)
[code] => 403
[message] => Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.
)
)
My below answer is no longer valid. Google now makes you use Firebase for URL Shortening. Easy to setup.
https://firebase.google.com/docs/dynamic-links/rest
So it turns out this old function that is displayed in multiple websites now needs the api key to be displayed in the URL section too for google to register the request to your account.
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
switched to this
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey);

Categories