How to extract public profile information from Facebook based on name using curl utility - api

I am trying to extract all public profile information i.e. name,birthday,location,gender, hometown,education, hobby using curl utility. I am using proper access token but I am only able to extract id,name,gender based on any name search using curl utility.
Can anybody help me on what exact steps to follow to extract all public information shared by a person in Facebook using curl utility.
An early reply is highly appreciated.

Set the URL first:
$url = https://graph.facebook.com/USER_ID/?fields=name,email,username,birthday
Now, call this function curlify
$contents = curlify($url);
This is the function:
function curlify($url)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_URL, $url);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
return $contents;
}
It will return the data in JSON format

Related

Binance Crypto Exchange API Error -1131 recvWindow must be less than 60000

I have a problem with my PHP script which was working before without problem. I dont know whay it have stop to work, because i dont have change anythink.
I am getting the error message:
array(2) { ["code"]=> int(-1131) ["msg"]=> string(37) "'recvWindow' must be less than 60000." }
So i did think ok easy i will just make the setting "recvWindow" smaller then "60000", but then the next error message comes also somethink with "recvWindow"
array(2) { ["code"]=> int(-1021) ["msg"]=> string(56) "Timestamp for this request is outside of the recvWindow." }
So what is wrong what must i do to make it work again? Here is the complete script which i have:
<?php
//--API Call
$nonce=time();
//--
$url='recvWindow=10000000000000000&timestamp='.$nonce;
//--
$sign=hash_hmac('SHA256',$url,$apisecret);
$url=$url.'&signature='.$sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$apikey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, "https://api.binance.com/api/v3/account?".$url);
$execResult = curl_exec($ch);
$Balances = json_decode($execResult, true);
var_dump($Balances);
?>
i did slove the problem, if you write the nonce parameter in milliseconds instead of seconds, then it works, and try to change the recwindow value also if you still get difficulties:
$nonce=round(microtime(true) * 1000); //time();

Get the current location from telegram using API

I have a telegram bot where I use custom buttons to interact with the users. I need now to get from then the current location using the GPS information. It is possible, using the telegram API to get the latitude and longitude from devices?
This is my PHP code:
if($text == '/start')
{
$botid = $xtokenid;
$chatid = $chat_id;
$reply = "Bem vindo ao EYB18, canal de informações online!";
$url = "https://api.telegram.org/bot$botid/sendMessage";
$keyboard = array('keyboard' => array(array("Localização")),'resize_keyboard' => true,'one_time_keyboard' => false,'request_location' => true);
$postfields = array('chat_id' => "$chatid",'text' => "$reply",'reply_markup' => json_encode($keyboard));
$str = str_replace('\\\\', '\\', $postfields);
print_r($str);
if (!$curld = curl_init()) {
exit;
}
curl_setopt($curld, CURLOPT_POST, true);
curl_setopt($curld, CURLOPT_POSTFIELDS, $str);
curl_setopt($curld, CURLOPT_URL,$url);
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curld);
curl_close ($curld);
}
Tks.
You are sending a keyboard which will ask users to send their location. If they press this button or even if they send any location from the map, your bot will get message object containing location object. Location object contains longitude and latitude.
Here is the full list of message object properties: https://core.telegram.org/bots/api#message
Here is location object: https://core.telegram.org/bots/api#location

Create a webhook using API in shopify

Here I stuck in shopify creating webhook through API
I am using cake php for creating public shopify app
Now I would like to create carts/update hook for my app using API here is my code
Cake php library : https://github.com/cmcdonaldca/CakePHP-Shopify-Plugin
File : ShopifyApiComponent.php
CODE :
public function createwebhook($shop_domain, $access_token){
$method = "POST";
$path = "/admin/webhooks.json";
$params = array("webhook" => array( "topic"=>"carts/create",
"address"=> $this->site_url."users/upUpdateCart",
"format"=> "json"));
$password = md5($this->secret.$access_token);//If your shopify app is public
$baseurl = "https://".$this->api_key.":".$password."#".$shop_domain."/";
$url = $baseurl.ltrim($path, '/');
$query = in_array($method, array('GET','DELETE')) ? $params : array();
$payload = in_array($method, array('POST','PUT')) ? stripslashes(json_encode($params)) : array();
$request_headers = in_array($method, array('POST','PUT')) ? array("Content-Type: application/json; charset=utf-8", 'Expect:') : array();
$request_headers[] = 'X-Shopify-Access-Token: ' . $access_token;
list($response_body, $response_headers) = $this->Curl->HttpRequest($method, $url, $query, $payload, $request_headers);
$this->last_response_headers = $response_headers;
$response = json_decode($response_body, true);
if (isset($response['errors']) or ($this->last_response_headers['http_status_code'] >= 400))
$body = $response['errors'];
else
$body = $response_body;
/*Debug the output in a text_file*/
$destination = realpath('../../app/webroot/execution_log') . '/';
$fh = fopen($destination."shopify_app.txt",'a') or die("can't open file");
date_default_timezone_set('GMT');
fwrite($fh, "\n\nDATE: ".date("Y-m-d H:i:s")."\n".$body);
fclose($fh);
/*Debug Code Ends*/
return (is_array($response) and (count($response) > 0)) ? array_shift($response) : $response;
}
and I called this function when I visit my app dashboard mean
Controller : Offers
function :dashboard
But its not seems to work because when I visit
https://test.myshopify.com/admin/webhooks.json its showing nothing but
If I am creating webhook through Admin->Setting->Notification then it show listing here https://test.myshopify.com/admin/webhooks.json
Please let me know how we can create webhook using API (cake php )
Shopify shows the list of webhooks through webhooks.json, those are created manually from the shopify admin. If you want to get the list of webhooks created through api then you need to run it from another browser or from a private browser (where shopify admin is not loged in)
Your link will be something like this -
https://api-key:api-password#shop-name.myshopify.com/admin/webhooks.json
Note: replace api key and password of your app and replace shop name in the link and try it in a new/private browser window.

REST HTTP DELETE without named arguments

I want to do:
curl -X DELETE -d '{"name":"flowx"}' 'http://somewhere/wm/staticflowentrypusher/json'
In perl:
my $browser = LWP::UserAgent->new;
my $url = 'http://somewhere/wm/staticflowentrypusher/json';
$browser->delete($url, '{"name":"flowx"}');
But I get:
Illegal field name '{"name":"flowx"}' at /home/user/perl5/lib/perl5/HTTP/Request/Common.pm line 115
Arguments in LWP::UserAgent::delete() are used to create headers not content. Use HTTP:Request for that:
my $browser = LWP::UserAgent->new;
my $url = 'http://somewhere/wm/staticflowentrypusher/json';
my $req = HTTP::Request->new(DELETE => $url);
$req->content('{"name":"flowx"}');
my $response = $browser->request($req);
say $response->content;

Youtube API: losing data via curl in PHP?

I'm sure that this is likely a simple solution, but I can't see my error. I'm making an API call to youtube to get some basic information on a youtube video using the video's ID; specifically what I want is the (1) title, (2) description, (3) tags, and (4) thumbnail.
When I load an API url via my web browser, I see all the data. I don't want to paste the entire response in this question, but paste the following url in your browser and you'll see what I see: http://gdata.youtube.com/feeds/api/videos/_83A00a5mG4
If you look closely you'll see media:thumbnail, media:keywords, content, etc. Everything I want is there. Now the troubles...
When I load this same url through the following functions (which I copied from the Vimeo api...), the thumbnail and keywords simply aren't there.
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
// youtube_get_ID is defined elsewhere...
$request_url = "http://gdata.youtube.com/feeds/api/videos/" . youtube_get_ID($url);
$video_data = simplexml_load_string(curl_get($request_url));
These functions do give me a response with some data, but the keywords and thumbnail are missing. Could anyone please tell me why my thumbnail and keywords are missing? Thank you for any help!
Here's the link for documentation on this.
Here's a function I wrote:
function get_youtube_videos($max_number, $user_name) {
$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/' . $user_name . '/uploads?max-results=' . $max_number);
$server_time = $xml->updated;
$return = array();
foreach ($xml->entry as $video) {
$vid = array();
$vid['id'] = substr($video->id,42);
$vid['title'] = $video->title;
$vid['date'] = $video->published;
//$vid['desc'] = $video->content;
// get nodes in media: namespace for media information
$media = $video->children('http://search.yahoo.com/mrss/');
// get the video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$vid['length'] = $attrs['seconds'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$vid['thumb'] = $attrs['url'];
// get <yt:stats> node for viewer statistics
$yt = $video->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$vid['views'] = $attrs['viewCount'];
array_push($return, $vid);
}
return $return;
}
And here's the implementation:
$max_videos = 9;
$videos = get_youtube_videos($max_videos, 'thelonelyisland');
foreach($videos as $video) {
echo $video['title'] . '<br/>';
echo $video['id'] . '<br/>';
echo $video['date'] . '<br/>';
echo $video['views'] . '<br/>';
echo $video['thumb'] . '<br/>';
echo $video['length'] . '<br/>';
echo '<hr/>';
}