Hi want to upload one single input.zip file as well as this xml descrition of file to the server.This is xml description part that I want to send in CURLOPT_POSTFIELDS,
<data_file>
<archive>"true"</archive>
<data_type_id> "42f7710d-9399-45d8-a61f-a018bb6c33f6""</data_type_id>
<data_file_name> "INPUT.zip"</data_file_name>
<description>..</description>
<uploaded>true</uploaded>
<job_id> job_id</job_id>
</data_file>
and this is libcurl part. I'm not sure if we can send both POST parameters and Postform in same request.
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headers=NULL;
static const char buf[] = "Expect:";
curl_global_init(CURL_GLOBAL_ALL);
/* Fill in the file upload field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "sendfile",
CURLFORM_FILE, filepathinput.c_str(),
CURLFORM_END);
/* Fill in the filename field */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "INPUT.zip",
CURLFORM_COPYCONTENTS, filepathinput.c_str(),
CURLFORM_END);
/* Fill in the submit field too, even if this is rarely needed */
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();
headers = curl_slist_append(headers, buf);
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERPWD,_loginCBstring.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xmldescription.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(xmldescription.c_str()));
_res = curl_easy_perform(curl);
if(_res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(_res));
curl_easy_cleanup(curl);
curl_formfree(formpost);
curl_slist_free_all (headers);
}
Thx a lot in advance!
Related
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×tamp='.$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();
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
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
i am having a problem with json codeigniter rest
i am making this call to the server and the problem its that its not closing the json tags
s, USA","clientUID":"7","email":null,"idipad":"2","dateModified":null},{"id":"19","uid":null,"name":"Wayne Corporation, Inc.","phone":"932345324","address":"Second st. 312, Gotham City","clientUID":"7","email":"waynecorp#gmail.com","idipad":"1","dateModified":null}]
its missing the final }
this is the code that creates the response :
$this->response(array('login'=>'login success!','user_admin_id'=>$user_id,'client'=>$client,'users'=>$users,'projects'=>$projects,'plans'=>$plans,'meetings'=>$meetings,'demands'=>$demands,'tasks'=>$tasks,'presences'=>$presences,'contractors'=>$contractors,'companies'=>$companies), 200);
this is the client call using curl :
$this->curl->create('http://dev.onplans.ch/onplans/index.php/api/example/login/format/json');
// Option & Options
$this->curl->option(CURLOPT_BUFFERSIZE, 10);
$this->curl->options(array(CURLOPT_BUFFERSIZE => 10));
// More human looking options
$this->curl->option('buffersize', 10);
// Login to HTTP user authentication
$this->curl->http_login('admin', '1234');
// Post - If you do not use post, it will just run a GET request
//$post = array('remember'=>'true','email'=>'admin.architect#onplans.ch','password'=>'password');
$post = array('remember'=>'true','email'=>'admin.architect#onplans.ch','password'=>'password');
$this->curl->post($post);
// Cookies - If you do not use post, it will just run a GET request
$vars = array('remember'=>'true','email'=>'manuel#ffff.com','password'=>'password');
$this->curl->set_cookies($vars);
// Proxy - Request the page through a proxy server
// Port is optional, defaults to 80
//$this->curl->proxy('http://example.com', 1080);
//$this->curl->proxy('http://example.com');
// Proxy login
//$this->curl->proxy_login('username', 'password');
// Execute - returns responce
echo $this->curl->execute();
// Debug data ------------------------------------------------
// Errors
$this->curl->error_code; // int
$this->curl->error_string;
print_r('error :::::LOGINN REMOTE:::::'.$this->curl->error_string);
// Information
$this->curl->info; // array
print_r('info :::::::::::::'.$this->curl->info);
the response belong to the rest api codeigniter from phil
/**
* Response
*
* Takes pure data and optionally a status code, then creates the response.
*
* #param array $data
* #param null|int $http_code
*/
public function response($data = array(), $http_code = null)
{
global $CFG;
// If data is empty and not code provide, error and bail
if (empty($data) && $http_code === null)
{
$http_code = 404;
// create the output variable here in the case of $this->response(array());
$output = NULL;
}
// If data is empty but http code provided, keep the output empty
else if (empty($data) && is_numeric($http_code))
{
$output = NULL;
}
// Otherwise (if no data but 200 provided) or some data, carry on camping!
else
{
// Is compression requested?
if ($CFG->item('compress_output') === TRUE && $this->_zlib_oc == FALSE)
{
if (extension_loaded('zlib'))
{
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) AND strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE)
{
ob_start('ob_gzhandler');
}
}
}
is_numeric($http_code) OR $http_code = 200;
// If the format method exists, call and return the output in that format
if (method_exists($this, '_format_'.$this->response->format))
{
// Set the correct format header
header('Content-Type: '.$this->_supported_formats[$this->response->format]);
$output = $this->{'_format_'.$this->response->format}($data);
}
// If the format method exists, call and return the output in that format
elseif (method_exists($this->format, 'to_'.$this->response->format))
{
// Set the correct format header
header('Content-Type: '.$this->_supported_formats[$this->response->format]);
$output = $this->format->factory($data)->{'to_'.$this->response->format}();
}
// Format not supported, output directly
else
{
$output = $data;
}
}
header('HTTP/1.1: ' . $http_code);
header('Status: ' . $http_code);
// If zlib.output_compression is enabled it will compress the output,
// but it will not modify the content-length header to compensate for
// the reduction, causing the browser to hang waiting for more data.
// We'll just skip content-length in those cases.
if ( ! $this->_zlib_oc && ! $CFG->item('compress_output'))
{
header('Content-Length: ' . strlen($output));
}
exit($output);
}
This answer was referenced from Github issue. Also raised by Pedro Dinis, i guest.
I met this problem today and take me long hours to search for the solution. I share here with hope to help someone like me.
The key is to replace around line 430 in the library file: REST_Controller.php :
header('Content-Length: ' . strlen($output));
by
header('Content-Length: ' . strlen("'".$output."'"));
UPDATE: The problem was solved here
Or you can just comment out the code, it will run fine. :)
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/>';
}