I want to use the Parse.com api to send push notifications but I need to send these push notifications from my CMS in PHP ...and not from Dashboard from parse.com. Its possible to integrate my CMS with parse`s dashboard? I have tried search in parse's doc but haven't found
here is the panel form
</div>
<div class="section_body">
<div id="push_errors" style="display: block;">Your message cannot be empty</div>
<div class="ui_action_button disabled" id="send_push"><span>Send now</span><i class="icon_send"></i></div>
</div>
</div>
https://parse.com/docs/push_guide#installations/PHP
$data = array("alert" => "Hi!");
ParsePush::send(array(
"channels" => ["PHPFans"],
"data" => $data
));
or:
$query = ParseInstallation::query();
$query->equalTo("design", "rad");
ParsePush::send(array(
"where" => $query,
"data" => $data
));
I think it is possible. Have a look at their docs here: https://parse.com/docs/push_guide#sending/PHP
For example (copied from docs):
"With the PHP SDK, the following code can be used to alert all
subscribers of the "Giants" and "Mets" channels about the results of
the game. This will display a notification center alert to iOS users
and a system tray notification to Android users."
$data = array("alert" => "Hi!");
ParsePush::send(array(
"channels" => ["PHPFans"],
"data" => $data
))
Related
There is currently 25k+ users we have in database. All users are subscribed to a common topic All.
I have two directories inside public_html. First is for API built in codeigniter. This API is used to provide data for all adnroid and iOS devices.
Second directory is for admin panel built in Laravel. We use it to upload data and also to send notification to firebase topics.
Both API and Admin Panel share same database.
If we send notification to topics which is not subscribed by much
users, there is no issue. But If I send notificaiton to a topic
which has much users It causes problems on our backend. The API
stops responding, or sometimes takes too long to respond.
Sometimes also admin panel stops responding too.
I am so confused because all the things are handled by firebase. I just make one API call.
Can anyone explain what's causing the problem?
Or any possible reason?
Update
use Kreait\Firebase\Messaging;
use Illuminate/Support/Http/Request;
trait UserTrait {
public function notify(Request $request, Messaging $messaging) {
$message_hi = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title_hi,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText_hi,
"image_url" => $request->image_url,
);
$message = array(
"notification_type" => $notification_type,
"notification_title" => $notification_title,
"icon_image" => $icon_image,
"notification_description" => $request->notificationText,
"image_url" => $request->image_url,
);
$commodityIdArray = $request->cId
//to send all
if($request->notification_type == 1) {
$messaging->sendAll([
['topic' => 'All', 'data' => $message],
['topic' => 'All_hi', 'data' => $message_hi],
]);
} else {
//to send to a fourite topic subscribed by some users
//Prepare Condition for both hindi and english users
$topic_condition = "";
$topic_condition_hi = "";
foreach($commodityIdArray as $topic) {
$topic_condition .="'".$topic."' in topics && ";
$topic_condition_hi.="'".$topic."_hi' in topics &&";
}
//send notification to hindi and english topics
$messaging->sendAll([
['condition' => substr($topic_condition, 0, -3), 'data' =>
$message],
['condition' => substr($topic_condition_hi, 0, -3), 'data' =>
$message_hi],
]);
}
}
Use Queue
You have to use a Queue which set your process in queue and when one process completes, the second one starts
you can also set number of retries of your process
I am trying to add subscriber to list through Getresponse api for single contact subscription to list i have to call api like this
$getresponse = new GetResponse(api key);
$result = $getresponse->addContact(listid,
$lead['name'],
$lead['email']
);
Now i want to add multiple emails at a single call, i cant use foreach loop for each contact, is there a function or endpoint to add multiple emails at a single call?
Getresponse official API shows only one contact.
https://apidocs.getresponse.com/v3/resources/contacts#contacts.create
As of now, there is no API endpoints for import contacts as bulk (csv or JSON).
Yes, Bala is correct. There is no such API method for GetResponse to insert multiple contacts. However, please check the below API codes to insert single contact to GetResponse.
include('GetResponseAPI3.class.php');
$getresponse = new GetResponse('your-getresponse-token-here');
$var = $getresponse->addContact(array
(
'name' => 'FirstName LastName',
'email' => 'emailid#something.com',
'dayOfCycle' => 0,
'campaign' => array('campaignId' => 'Campaign-id'),
'ipAddress' => 'XXX.XXX.XX.XX'
)
);
var_dump($var);
Now I posting a single photo to wall like this:
$response = $facebook->api("/$group_id/photos", "POST", array(
'access_token=' => $access_token,
'message' => 'This is a test message',
'url' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
)
);
It works fine, but can I somehow post a multiple photos, something like this:
You can now publish multiple images in a single post to your feed or page:
For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false.
You'll get an ID for each photo you upload like this:
{
"id": "10153677042736789"
}
Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo
$response = $facebook->api("/me/feed", 'POST',
array(
'access_token=' => $access_token,
'message' => 'Testing multi-photo post!',
'attached_media[0]' => '{"media_fbid":"1002088839996"}',
'attached_media[1]' => '{"media_fbid":"1002088840149"}'
)
);
Source: Publishing a multi-photo story
You can make batch requests as mentioned here: https://stackoverflow.com/a/11025457/1343690
But its simple to loop through your images and publish them directly.
foreach($photos as $photo)
{
//publish photo
}
Edit: (regarding grouping of photos on wall)
This grouping is done by facebook automatically if some photos are uploaded into the same album.
Currently you cannot create an album in a group via Graph API - it is not supported (as of now), see this bug.
But you can do this - create an album manually, then get the album_id by-
\GET /{group-id}/albums, then use the the code with album_id instead of group_id-
foreach($photos as $photo){
$facebook->api("/{album-id}/photos", "POST", array(
'access_token=' => $access_token,
'name' => 'This is a test message',
'url' => $photo
)
);
}
I've tested it, see the result-
Actually you can upload a multi story photo(I did it using Graph Api and PHP) but the problem comes if you need scheduled this post.Your post is schedule but also it shows on the page's feed.
P.S. I'm using Graph Api v2.9
PHP Code
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
You will need to upload each photo first with published state to false, and then use the ID's of the unpublished photos to the /me/feed endpoint to schedule the photo. The schedule needs to be within the 24 hours from the time the photos are uploaded as facebook deletes all unpublished photos in 24 hours.
Ref:
https://developers.facebook.com/docs/graph-api/photo-uploads/
There is no way to publish more than one photo in the same graph API call.
See documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos
I am trying to create tickets on my Zendesk and that is working fine. However i do not want Zendesk to email the creator of the tickets (his or her email). Is this possible?
The idea is i have a contactForm widget on my site, i want the submits from this form to create tickets in my Zendesk.
Creating tickets is currently working using this code:
$zendesk = new zendesk(
$row->api_key,
$row->email_address,
$row->host_address,
$suffix = '.json',
$test = false
);
$arr = array(
"z_subject"=>"Offline Message",
"z_description"=> $r->contact_msg,
"z_recipient"=>$r->contact_email,
"z_name"=>$r->contact_name,
);
$create = json_encode(
array('ticket' => array(
'subject' => $arr['z_subject'],
'description' => $arr['z_description'],
'requester' => array('name' => $arr['z_name'],
'email' => $arr['z_requester']
))),
JSON_FORCE_OBJECT
);
$data = $zendesk->call("/tickets", $create, "POST");
Any ideas?
Totally possible! You need to add some conditions to the trigger "Notify requester of received request" in Zendesk - Trigger setting to prevent zendesk from sending email. For ex:
Ticket : Channel - Is Not - Webservice (API)
Ticket : Tags - Contains one of the following - "offline message"
You could use another API endpoint "Ticket Import" https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_import/
It's do not send notifications
I'm using the following to post a message on my Facebook page:
$attachment = array(
'access_token' => $access_token,
'message' => 'This is a test Message 4:',
'name' => "This is a test Name 4",
'link' => "http://slashdot.org/",
'description' => "This is a test Description 4"
);
$ret_code=$facebook->api('/me/feed', 'POST', $attachment);
This works great.
How do I delete the same post using the facebook GRAPH api? I read the docs and it says to issue a POST like:
https://graph.facebook.com/COMMENT_ID?method=delete
To test I set this up in a simple form with submit button, POSTing the data to https://graph.facebook.com/COMMENT_ID?method=delete (substituting COMMENT_ID fro the 11111111111_111111111111 id returned from the original publish call. This returns "This API call requires a valid app_id".
What is the correct way to issue a DELETE command?
Since you are using the php-sdk you just issue this call:
$facebook->api("/COMMENT_ID","DELETE");
You can use the following code:
Http::post('https://graph.facebook.com/'.$fb_action_id, array('method'=>'delete', 'access_token'=>$your_app_access_token));
This post will return a boolean value, true if successed and false if failed.
Its been discussed here Facebook SDK and Graph API Comment Deleting Error
you need to pass the access token too. You can delete all the milestones of a page like follows:
$milestones = $facebook->api('/PAGE_ID/milestones');
foreach($milestones[data] as $milestone)
{
echo $milestone['id'];
$args = array(
'access_token' => $pages_access_token
);
$deleted = $facebook->api($milestone['id'],"delete",$args);
if($deleted)
{
echo " <font color=\"green\">OK</font><br>";
}
else
{
echo " <font color=\"red\">ERR</font><br>";
}
}