When I try to subscribe a user on mailchimp, it gives an error response pasted below:
‹<»nÃ0E…Вű2tòèt+ŠB‘[€.I¹0‚ü{i»è(Þ‹ÃC=Œ¬3šÁL"ómÀS‘úìbòSÌsïk¶¡ú–±ˆ“X‹ýÏìØb#¶HTé<¦Êìhµ¦3%mÜ·²¸\‘k#±R›áåréL#Q˜ß'ú+·[Ž"À×–”pCØQNÇ=¼V‚{ÄÎ<£÷èá#qŒ¢¸Ó®Å'pDníuu,º¼øML_Gl†‡ÙQÇ4£1n•+~·H±§?H¸«ÌT½;€ÛW|¹TÍóóùÿÿI*¯Q`
Here is the PHP code:
$apiKey = 'YOUR API KEY';
$listId = 'YOUR LIST ID';
$url2 = 'https://us12.api.mailchimp.com/3.0/lists/'.$listId.'/members/';
$args = array(
'email' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));
function syncMailchimp($url,$apiKey,$args) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_USERPWD, "user apikey:" . $apiKey);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($args));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Is the server sending bad data or is client side using a wrong encoding and how do I fix it?
Changing the key called email to email_address appears to have fixed it. Perhaps that bad key caused the server to puke.
$args = array(
'email' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));
to
$args = array(
'email_address' => 'abc#xyz.com',
'status' => 'subscribed',
'merge_fields' => array(
'first_name' => 'WOW',
'last_name' => 'WOW',
'mobile'=>'',
'message'=>'',
'ID'=>'000'
));
Related
I have a OneSignal setup for sending notification to specific users via external user id as follows
$fields = [
'app_id' => env( 'app.onesignalAppKey' ),
'priority' => 10, // High priority.
'include_external_user_ids' => [ md5( $contact['email'] ) ],
'channel_for_external_user_ids' => 'push',
'headings' => [ 'en' => $this->subject ],
'contents' => [ 'en' => $this->message ],
'url' => [ 'en' => base_url( $this->args['log_extra']['url'] ) ]
];
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, env( 'app.Onesignalurl'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic '. env( 'app.onesignalAPI' )));
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);
While testing I'm receiving notification, but clocking the notification redirect to wrong url.
https://example.com/onesignal/{"en"=>"https://example.com/correct-path"}
OneSignal service worker installed with scope set to /onesignal/
Am I don't something wrong here..?
Just put the URL as string in $fields array, not an array.
like:
'url' => base_url( $this->args['log_extra']['url'] ),
I am making a flutter app and I am using Firebase to do push notifications.
I am not sure what is going wrong here. It looks like it should work I think but I get no response back. Am I missing something?
Here is my code:
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$token = $_POST['token'];
$notification = [
'title' => 'title',
'body' => 'body of message.',
'icon' => 'myIcon',
'sound' => 'mySound'
];
$extraNotificationData = ["message" => $notification, "moredata" => 'dd'];
$fcmNotification = [
//'registration_ids' => $tokenList, //multple token array
'to' => $token, //single token
'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_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
I am getting notification to all android device except samsung mobile.
This problem started after I updated url from "https://android.googleapis.com/gcm/send" to
"https://fcm.googleapis.com/fcm/send" because gcm suddenly stopped sending notification to all devices..
After updating url,notification is not going to samsung devices
I am not getting wheee is the problem.Please help me with solution
Thank you
here is my fcm code in php
$msg = array(
'message' => json_encode($parsedMsg),
'title' => '',
'subtitle' => '',
'tickerText' => '',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
if(count($registrationIds) == 0){
return json_encode(array('success' => 0, 'failure'=>0));
}
$fields = array(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array(
'Authorization: key=' . API_ACCESS_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_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
I'm trying to update my code for subscribing new users to my MailChimp newsletter.
I would like it to add the user to a group, so that I can distinguish between users when sending out newsletters. This code, however, subscribes the user but does not add it to any group. What am I doing wrong? I am using the MailChimp API 3.0.
My code:
$apiKey = 'XXXX';
$list_id = 'XXXX';
$memberId = md5(strtolower($data['email']));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . $memberId;
$json = json_encode(array(
'email_address' => $data['email'],
'status' => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => array(
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname'],
'GROUPINGS' => array(
0 => array(
'name' => 'Interests',
'groups' => array( $data['tag'] ),
),
),
),
));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
You are passing Interest grouping in the wrong array.
you need to pass the interest group id in interests array with value as true.
$json = json_encode(array(
'email_address' => 'test#example.com',
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => 'FirstName',
'LNAME' => 'LastName',
),
'interests' => array(
'9143cf3bd1' => true,
'789cf3bds1' => true
),
));
You will get the id of interest groups [9143cf3bd1,789cf3bds1 in above example] of the list by requesting to this URL
/lists/{list_id}/interest-categories
see doc here
If you want to remove the subscriber from the group, you need to set its value to false in your update request.
I need to be able to post to the wall of my page, i have given offline_permissions and I got it to post to my profile wall but I need it to post to my pages wall.
Anyone know how to do this, where does my code need changing? thanks
<?php session_start();
$fb_page_id = xxxxxxxxxxxxxxxx;
$fb_access_token = 'xxxxxxxxx|xxxxxxxxxxxxxxxxxx-xxxxxxxx|xxxxxxxxxxxxxxxxxxxxxxx';
$url = 'https://graph.facebook.com/'.$fb_page_id.'/feed';
$attachment = array(
'access_token' => $fb_access_token,
'message' => 'message text',
'name' => 'name text',
'link' => 'http://domain.com/',
'description' => 'Description Text',
'picture'=>'http://domain.com/logo.jpg',
);
// set the target url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$go = curl_exec($ch);
curl_close ($ch);
?>
$config = array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
'allowSignedRequest' => false //optional but should be set to false for non-canvas apps
);
$facebook->api('/me/feed', 'POST',
array(
'link' => 'www.example.com',
'message' => 'Posting with the PHP SDK!'
));
https://developers.facebook.com/docs/php/howto/postwithgraphapi/