I am having trouble adding a note to a subscriber using Mailchimp's API. Here's what I have:
$email = 'some#email.com';
$list = '123456';
$note = 'This is an example of a note.';
$apiKey = 'MY-API-KEY';
$memberId = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$list.'/members/'.$memberId.'/notes';
$json['note'] = $note;
$json = json_encode($json);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['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);
if ($httpCode == 200) {
return true;
} else {
return false;
}
Any ideas why these notes would not be saved? I've made sure the API key, the list ID and the email address are all correct.
The documentation page is here: https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/notes/
Related
I am using Laravel 5.5 to develop a Student Project. There is an option in my project where the publication information can be found by searching with DOI. I am using the below code but it stops working.
function doi_url($doi)
{
return "http://dx.doi.org/" . $doi;
}
function get_curl($url)
{
$curl = curl_init();
$header[0] = "Accept: application/rdf+xml;q=0.5,";
$header[0] .= "application/vnd.citationstyles.csl+json;q=1.0";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$citation_string = curl_exec($curl);
curl_close($curl);
return $citation_string;
}
function get_json_array($json)
{
return json_decode($json, true);
}
echo doi_url($doi);
echo get_curl($doi_url);
echo get_json_array($json);
echo $json_array["container-title"];
echo $json_array["page"];
echo $json_array["issue"];
echo $json_array["ISSN"];
echo $json_array["URL"];
echo $json_array["issued"]["date-parts"][0][0];
Please help me is there any other procedure to get publication data?
I want use that error in my code, ex.
if(Not Found In Database) then
show alert"Data Not Found In Database"
How to make that error include to my variabel?
*Note: I'm using Laravel-7
You can try
throw new \Exception("error");
Edit, adding function for check exist file by use curl
function checkUrlExistFile($url): bool {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_exec($ch);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($info == '200') return true;
return false;
}
And Example
if (!checkUrlExistFile($url)) {
throw new \Exception("error");
}
First check you have record or not:
$data = model::all();
if($data == NULL) {
echo "<script>alert('data not found')</script>"
}
public function payment(Request $request){
//===============Getting Access Token from N-Genius Platform Network===============================================
$apikey = "api-key"; // enter your API key here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-gateway.sandbox.ngenius-payments.com/identity/auth/access-token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"accept: application/vnd.ni-identity.v1+json",
"authorization: Basic ".$apikey,
"content-type: application/vnd.ni-identity.v1+json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"realmName\":\"ni\"}");
$output = json_decode(curl_exec($ch));
$access_token = $output->access_token;
//===============END Getting Access Token from N-Genius Platform Network=============================================
//===============N-Genius Payment Gateway will redirect to the pay page =============================================
$postData = new StdClass();
$postData->action = 'Sale';
$postData->amount = new StdClass();
$postData->amount->currencyCode = 'AED';
$postData->amount->value = 1 * 100;
$postData->language = 'en';
$postData->emailAddress = 'form user email';
$postData->billingAddress['firstName'] = 'form first name';
$postData->billingAddress['lastName'] = 'form last name;
$postData->merchantAttributes['redirectUrl'] = 'redirection page route';
$token = $access_token;
$json = json_encode($postData);
$outlet = "outlet-id";
$token = $access_token;
$json = json_encode($postData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-gateway.sandbox.ngenius-payments.com/transactions/outlets/'.$outlet.'/orders');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Content-Type: application/vnd.ni-payment.v2+json',
'Accept: application/vnd.ni-payment.v2+json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$output = json_decode(curl_exec($ch));
$order_reference = $output->reference;
$order_paypage_url = $output->_links->payment->href;
header("Location: ".$order_paypage_url); // execute redirect
//die();
curl_close ($ch);
//===============END N-Genius Payment Gateway will redirect to the pay page =============================================
}
Anyone can help me Please. Please Guide me How to integrate ngenius-payment gateway to laravel app Their documentation not enough to integrate with laravel. i am planing to choose with making payments from their websites, and return back to us with a return URL.
did you get the accessToken?
if yes then try with this post data
{
"action": "SALE",
"amount": {
"currencyCode": "AED",
"value": 1700
},
"merchantAttributes" : {
"redirectUrl" : "url",
"skipConfirmationPage": true,
"cancelText": "Go to Homepage"
},
"emailAddress": "test11#order.com",
"merchantOrderReference": "test-12"
}
I have two domain one is stgportal and another is stg.I want to upload image from stgportal to stg.My code is given below
move_uploaded_file($_FILES['ThumbnailImage']['tmp_name'],"http://stg.eminencesystem.com/assets/images/th/".$thimg)
show the error: failed to open stream: HTTP wrapper does not support writeable connections
how can i resolve this issue?
You can use CURL to send file to another server securely like this
At stgportal side
function sendImageToServer($path = "", $file = null)
{
$post_url = "http://stg.eminencesystem.com/post_file";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $post_url);
//most importent curl assues #filed as file field
$post_array = array(
"folder_name" => $path
);
if ((version_compare(PHP_VERSION, '5.5') >= 0)) {
$post_array['file'] = new CURLFile($file);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, TRUE);
} else {
$post_array['file'] = "#" . $file;
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
return $response;
}
At stg side
$ImagePath = "/var/www/html/assets/";
$files = $_FILES;
$folder_name = utf8_decode($_POST['folder_name']);
$savepath = $ImagePath . $folder_name . $files['name'];
copy($file['tmp_name'], $savepath);
echo 1;
exit;
I'm having a problem finding the share count of a website in google+.I've done the facebook, tweeter etc but i cant figure out how to do it in google+. I have searched this solution but only it returns 0.
function get_plusones($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$curl_results = curl_exec ($curl);
curl_close ($curl);
$json = json_decode($curl_results, true);
return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}
What have i done wrong?Any solution?
Found the solution didn't put www in front of the url.