Documentation for Google FIT REST API dataset:aggregate - google-fit

I am trying to get data from Google Fit using REST API. I am able to get individual data points for steps and calories through the documented REST APIs. However,I want them aggregated by day. I see the following resource in the Oauth2 playground:
https://www.googleapis.com/fitness/v1/users/{userId}/dataset:aggregate
However, I was not able to find any documentation on how to use this. Has anyone been successful in using this REST resource? Any pointers to the documentation / any examples would really help.
Thanks,

This is how i solved this REST call & its working code in my project.
$AccessToken = "TOKEN";
Data['aggregateBy'] =array(["dataTypeName"=>'com.google.step_count.delta',"dataSourceId"=>'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps']);
$Data['bucketByTime']['durationMillis'] =86400000;
$Data['startTimeMillis'] =1487721600000;
$Data['endTimeMillis'] =1487772000000;
$JsonData = json_encode($Data);
$ApiUrl = 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate?access_token='.$AccessToken;
$Ch = curl_init();
curl_setopt($Ch, CURLOPT_URL, $ApiUrl);
curl_setopt($Ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($Ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($Ch, CURLOPT_HEADER, 0);
curl_setopt($Ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($Ch, CURLOPT_POST, 1);
curl_setopt($Ch, CURLOPT_POSTFIELDS, $JsonData);
$Result = curl_exec($Ch);
curl_close($Ch);
print_r($Result);

Related

How to encode foreign characters for importing to shopify via API using PHP and CURL

Im trying to import our customers from our Magento site to Shopify via the API. Im using PHP and CURL
My script works fine for most of our customers but its having trouble with any names that have foreign characters in, I get the question mark symbol when echoing the variables with the foreign characters in and the API call just fails and no customer is created.
Strangely if I copy the JSON object into Insomnia and run the API call it works fine even with the foreign characters so Im assuming Insomnia is adding some encoding that my script isnt.
Im assuming I have an issue with character set but not sure what I need to change it to or if I've set it wrong.
Heres my Curl code:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_string);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
and Ive also tried declaring it as UTF-8
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=UTF-8'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_string);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
Is there anything obvious Ive got wrong?
Thanks
If you are using a mysqli database connection to fetch the data from Magento, you may need to set the charset of the connection to utf8 so that PHP gets the data correctly from the database:
$mysqli->set_charset("utf8")
Sounds like you are forgetting to deal with UTF-8 properly. Whenever you see a question mark it shows you an encoding error. It means your source data was mangled. It means the source data was UTF-8, and then you read it as ASCII which cannot do UTF-8 properly, so then Shopify is going to see garbage as it works off of UTF-8 encoding.

request a web service from laravel that returns a json object

I have this Url : https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e
when I request it from browser it gives me this response:
{"ip_address":"188.225.179.138","country":"Palestinian Territory, Occupied","country_code":"PS","continent":"Asia","continent_code":"AS","city":"Ramallah","county":null,"region":null,"region_code":null,"timezone":"GMT+2","owner":"COOLNET NEW COMMUNICATION PROVIDER","longitude":35.2,"latitude":31.9}
how can I invoke this url from laravel?
note that I tried this code, but it didn't work.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
curl_close($ch);
dd($data);
Thanks in advance.
In the Curl you shall do this Easy 5 steps
Step 1
Initiate the Curl $cSession = curl_init();
Step 2
Define the Curl Url
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
Step 3
Execute the Curl
$result=curl_exec($cSession);
Step 4
Close the Curl Connection
curl_close($cSession);
Step 5
Print the Result
echo $result;
Putting all together
<?php
$cSession = curl_init();
curl_setopt($cSession,CURLOPT_URL,"https://ipfind.co/?ip=188.225.179.138&auth=dde7cf52-2294-47e3-adb2-1e559099527e");
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
$result=curl_exec($cSession);
curl_close($cSession);
echo $result;
?>
There is a PHP package for getting an IP address for IP Find that you can install with composer here that works great with Laravel.
https://github.com/tenfef/ipfind-php/

curl request to google places api returns "bool(false)"

I've tried using the Javascript version of google places API, but now I'd like to move the code to server side with an API key. I've tried using all possible permutations and combinations of the curl request, but couldn't find a solution to it.
$url = urlencode('https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' . $input . '&types=establishment&location=13.052415, 80.250824&radius=500&sensor=true&key=KEY');
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
NOTE: I've used my app's KEY in the "key" params.
Response I get => bool(false)
Any suggestions?

Post data using curl without showing the redirect URL in adress bar

Below is the my curl for senting some parameters to a url.But the parameter I m senting has sensitive datas like passwords and other things.But during posting the datas will be showed in the adress bar as redirect url.How to avoid this?.What to do to sent data without showing it in address bar?
$parameters='MerchantId='.$merchantId.'&Password='.$Password.'&ReferenceNo='.$ReferenceNo.'&RemoteIP='.$RemoteIP.'&Amount='.$Amount.'&BankId='.$BankId.'&Checksum='.$checksum.'&Name='.$Name.'&MobileNo='.$MobileNo.'&Email='.$Email;
//set POST variables
$url = 'https://payment.essecom.com/NetBanking/PayDirekt.jsp?'.$parameters;
//header('Location: '.$url);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/plain', 'Content-length: 900'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
echo curl_exec($ch);
curl_close($ch);
}
It's pretty easy to not include headers in output. Just add option CURLOPT_HEADER and set it to false. But without headers how can you be sure that request is completed successfully?

Scrape a particular area of site content With a Secure Login

I am trying to scrape some particular text of a website which is login secured
here is the tutorial on this using curl
http://www.digeratimarketing.co.uk/2008/12/16/curl-page-scraping-script/
But I am unable to implement this into my curl codes
here is my curl script
$url = "http://aftabcurrency.com/login_script.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$cookie = 'cookies.txt';
$timeout = 30;
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch,CURLOPT_POSTFIELDS,"user_name=user&user_password=pass&passcode=code");
$result = curl_exec($ch);
curl_close($ch);
$source = $result;
if(preg_match("/(CC3300\">)(.*?)(<\/font>)/is",$source,$found)){
echo $found[2];
}else{
echo "Text not found.";
}
for example in aftabcurrency.com I only wish to scrap only "Our Services Matters!" (this text changes every day)
what I would do is to "cut out" a text between start and beginning... in the source the text is starting by a text color 613A75 and ands with the closing < /font> tag.. here is a regex solution:
$source = file_get_contents("http://aftabcurrency.com/index.php");
if(preg_match("/(613A75\">)(.*?)(<\/font>)/is",$source,$found)){
echo $found[2];
}else{
echo "Text not found.";
}
if you want to do this with your text inside member area, add my source here to your source and replace the $source = file_get_contents... with $source = $result
there is also other way to do this, DomDocument and xpath or simple strpos / strstr / substr php functions.