facebook share not fetching og:image - image

I have added FB share dialog to share images on facebook. I have tried all possible solutions but its still not fetching image. After sometime for some posts it works but not most of the times.
I have forcefully scraped the urls using php curl
$current_url = get_permalink();
$curl = 'https://graph.facebook.com/';
$return = getCurlRequest($curl,'id='http://viralsyndicator.com/best-spring-fishing-lures-of-2018-bass-pro-shops-challenge/'&scrape=true&access_token=token');
function getCurlRequest($url,$postdata=""){
//echo $url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:','Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
//echo '<pre>';print_r($response);
curl_close($ch);
if ($response == false){ return false;}
return $response;
}
This page always has og:image meta tag but still it does not work. When I go to fb debugger tool and I debug it, first time it says og:image should be provided, scraping it after 2-3 times it starts working.
I have tried og:image:width properties as well.
I am using wordpress plugin to share, I have used FB.ui as well manually and it worked for sharing but I am also using FB comment plugin and when I am commenting and checking checkbox to post on fb as well, its not publishing image and I don't know how to use FB comment plugin manually similarly share to fetch correct image instead of logo.
FB.ui({
method: 'share',
href: '<?php echo $postUrl; ?>',
picture: "http://viralsyndicator.com/wp-content/uploads/2018/02/0-199-670x377_c.jpg",
title: 'title',
description: '<?php echo $decodedPostTitle; ?>',
}, function(response) {});
I dont know how to solve this FB issue.Please help guys.
Thanks

Related

omnipay/paypal and notifyUrl issue

Dear stackoverflow community,
Recently PayPal contacted me to upgrade my 'old-style' CodeIgniter e-commerce cart (an old standard paypal gateway with a simple form to related paypal endpoint) to a solution with access token and client_id + secret. I used omnipay-paypal, following a guide like this:
https://artisansweb.net/paypal-payment-gateway-integration-in-php-using-paypal-rest-api/
And everything seems working fine, but with old standard cart I used a notifyUrl to send payment post data to a controller that made something like this:
foreach ($_POST as $key => $value) {
$request .= '&' . $key . '=' . urlencode(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
}
$curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
If that $response is VERIFIED, I enable related order for delivery (paid).
Issue is that notifyUrl isn't triggered at all with Omnipay and this avoids to fit the shoe.
I tried to setup notifyUrl parameter on purchase, completePurchase method, but nothing to do: no call is sent after payment confirmation and no payment data in the related $_POST object.
Someone could give me some hint or help?
I tried to force the notifyUrl in any possible way, but after transaction is complete and payment confirmed, the notifyUrl is not receiving the expected data with post.

Quick q. Mailchimp API 3.0

Can i use the first script or i need to use the curl option for mailchimp 3.0? I read some posts that the first one may be depreciated.. is that correct? Note that i'm not running on WordPress. Thank you for your fast answers.
<?php
require("vendor/autoload.php");
use \DrewM\MailChimp\MailChimp;
$mc = new MailChimp('apikey');
$email = $_POST['email'];
$subscriber_hash = $mc->subscriberHash($email);
$response = [];
$list_id = 'listid';
$resp = $mc->get("/lists/$list_id/members/$subscriber_hash";
if ($mc->success()) {
$response['message'] = 'Thank you for subscribing to the mailing list';
// User successfully subscribed - set HTTP status code to 200
http_response_code(200);
} else {
$response['message'] = $mc->getLastError();
// User not subscribed - set HTTP status code to 400
http_response_code(400);
}
// Return json-formatted response
echo json_encode($response);
?>
Or should i use this one?
function mc_checklist($email, $debug, $apikey, $listid, $server) {
$userid = md5($email);
$auth = base64_encode( 'user:'. $apikey );
$data = array(
'apikey' => $apikey,
'email_address' => $email
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'.api.mailchimp.com/3.0/lists/'.$listid.'/members/' . $userid);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '. $auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
if ($debug) {
var_dump($result);
}
$json = json_decode($result);
echo $json->{'status'};
}
This row is only for stackoverflow not alowing me to post that much code without including more details.
The first is not deprecated. It uses this wrapper to make API calls using the same API version that the second block of code uses. It's just simpler to work with so you don't have to write separate CURL requests for every call. You can also take a look at some of its source code and notice that it uses CURL anyway to make its calls.
So either way will use CURL, and whichever option you choose is simply a matter of preference.
Hopefully that clears it up for you!

Codeigniter hit an url and get back

I am using codeigniter 3.0 in my webapp. I want to hit an URL then get back to a view. Lets say on clicking a button, I want to hit an API then return back to the same view with success message. Can anyone help?
My API is http://wmlab.in/api/getData.php?username=web
I tried file('http://wmlab.in/api/getData.php?username=web') but it is not working.
use curl to do that and also install curl if your server did not have curl.
url="http://wmlab.in/api/getData.php?username=web";
function getUrlContent($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$data = curl_exec($ch);
echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ($httpcode>=200 && $httpcode<300) ? $data : false;
}
$content=getUrlContent($url);
echo $content;
You can use file_get_contents('http://wmlab.in/api/getData.php?username=web') or can use curl;
For Curl use below code:-
$channel = curl_init();
curl_setopt( $channel, CURLOPT_URL, "http://wmlab.in/api/getData.php?username=web" );
curl_setopt( $channel, CURLOPT_RETURNTRANSFER, 1 );
$response= curl_exec ( $channel );
curl_close ( $channel );
// after curl response redirect to othe page
redirect('anypage');
For file get content use below code:-
$response=file_get_contents('http://wmlab.in/api/getData.php?username=web')
// after response redirect to othe page
redirect('anypage');
Hope it will help you.
it should be work
$result=file_get_contents('http://wmlab.in/api/getData.php?username=web');

Square Connect API - image upload - Empty Reply From Server code 52 error

Trying to get square connect API image upload working using PHP.
I used the square connect API guide: docs.connect.squareup.com/api/connect/v1/#post-image
Tried two different ways based on what I found on StackOverflow and Google searching.
Method 1) regular curl request:
https://gist.github.com/delalis/17c3c111e3b42df127ed
Method 2) using CURLFile (php >=5.5 only)
https://gist.github.com/delalis/5c7ecc2aaa024927b360
Both methods gave me this empty reply from server error:
Error: "Empty reply from server" - Code: 52
I am able to connect to square to do other functions no problem, image uploading however is proving to be quite difficult!
Any help would be greatly appreciated.
Here's a working PHP example that I usually share with people:
https://gist.github.com/tdeck/7118c7128a4a2b653d11
<?php
function uploadItemImage($url, $access_token, $image_file) {
$headers = ["Authorization: Bearer $access_token"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "#$image_file;type=image/jpeg"]);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$return_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
print "POST to $url with status $return_status\n";
curl_close($ch);
return $data ? json_decode($data) : false;
}
print_r(
uploadItemImage(
'https://connect.squareup.com/v1/me/items/ITEM_ID/image',
'ACCESS_TOKEN',
'IMAGE_FILE.jpg'
)
);
?>

send post include text and image by xmlrpc to wordpress

Im looking for a way to send remotely content(text and image ) by xmlrpc to wordpress but i couldn't find yet, im going to sent remotely content (text and image) over 100 post per minute to wordpress, whats the best way to do it? thanks so much
Use XMLRPC. Something like this:
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.newPost',$params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $rpcurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);

Resources