Google+ share count error - google-api

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.

Related

How do I find publication information by searching by doi in Laravel?

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?

POST requests require a Content-length header in laravel

$output = Curl::httpGet("https://bhleh.com/emailstorage", "POST", $params);
return $output;
this is in my laravel but when ever i try to run this i get an error saying
411. That’s an error.
POST requests require a Content-length header. That’s all we know.
i tried adding header files in my middle ware folder but nothing seems to work.
i figured out that the Content-length header isn't included in laravel (i think so not so sure) so how would i add it
please note i am very new to laravel
this fix to this is that this i replaced the whole code with this
$data_string = json_encode($params);
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return $result;
I was facing the same issue but I was not sending CURLOPT_POSTFIELDS as per the API endpoint. I don't need to send any variable but when I send CURLOPT_POSTFIELDS with a blank array it started working.
$data_string = array();
$ch = curl_init('https://bhleh.com/emailstorage');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data_string));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
);
$result = curl_exec($ch);
return $result;

Adding a note for a subscriber using Mailchimp API

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/

How you should retrieve google plus +1 count for an url?

Using the rpc method:
$url = 'http://www.google.com';
$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);
echo intval( $json[0]['result']['metadata']['globalCounts']['count'] );
or using the +1 button scrapping method?
$url = 'http://www.google.com';
$result = file_get_contents('https://plusone.google.com/_/+1/fastbutton?url='.urlencode($url));
preg_match( '/window\.__SSR = {c: ([\d]+)/', $result, $matches );
echo (isset($matches[0])) ? (int) str_replace('window.__SSR = {c:', '', $matches[0]) : 0;
Having an explanation of differences or possible side effects would be great.
Note: Both methods works as 2014/04/05.
Given that neither are official / supported by Google, I'd propably use the first method and fallback to the second in case that fails. The second method is more error-prone, since you're parsing source code that can change at any time (not that calling a service you're not supposed to be calling is any better, but apparently there are no other options).

how to maintaining session when using more than one curl script

i used curl to login a website. the code is:
<?php
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.xxxx.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=xx&pwpwd=111111';
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
$url='http://bbs.xxx.com/userpay.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<li> (.*)<\/li>/",$contents,$arr);
echo $arr[1];
curl_close($ch);
?>
it works fine,but the problem is that when i make it into two files(a.php,b.php).it does not work.
i make a.php like:
<?php
$cookie_file = tempnam('./temp','cookie');
$login_url = 'http://bbs.xxxx.com/login.php';
$post_fields = 'cktime=31536000&step=2&pwuser=xx&pwpwd=111111';
$ch = curl_init($login_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);
curl_close($ch);
?>
and b.php like:
<?php
$cookie_file = tempnam('./temp','cookie');
$url='http://bbs.xxx.com/userpay.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
preg_match("/<li> (.*)<\/li>/",$contents,$arr);
echo $arr[1];
curl_close($ch);
?>
i first visit a.php,then visit b.php. it dose not work!!!!
can any one help me?
it that different curl scripts can not share session???
In the first CODE you use one $cookie_file for two requests.
You should use same $cookie_file in a.php and b.php.
But you create two different $cookie_file with
$cookie_file = tempnam('./temp','cookie');
You create one in a.php.
Then you create another different one in b.php.

Resources