i have problem with this website api,
i used this code to generate a shorturl by this api but always i got a White Page Screen without any content!
Please Help me to generate a url:
<?php
function bucksapi($longUrl)
{
$bucksapi = 'myapipass';
$sinoone = 'myusername';
$adts = '2';
$contype = '1';
$domainss = 'linkbucks.com';
$postData = array('originalLink' => $longUrl, 'user' => $sinoone, 'apiPassword' => $bucksapi, 'contentType' => $contype, 'adType' => $adts, 'domain' => $domainss);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.linkbucks.com/api/createLink/single');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
//As the API is on https, set the value for CURLOPT_SSL_VERIFYPEER to false. This will stop cURL from verifying the SSL certificate.
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
$json = json_decode($response);
curl_close($curlObj);
return $json->link;
}
?>
and this for printing the short link:
<?php
$long_url = "http://google.com";
echo bucksapi($long_url);
?>
Based on your work.
<?php
function curl($url, $cookies= NULL, $post = NULL)
{
$ch = #curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (!empty($cookies)) {
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
$page = curl_exec($ch);
var_dump($page);
curl_close($ch);
return $page;
}
function bucksapi($longUrl, $bucksapi, $sinoone, $adts = '2', $contype = '1')
{
$postData = array(
'originalLink' => $longUrl,
'user' => $sinoone,
'apiPassword' => $bucksapi,
'contentType' => $contype,
'adType' => $adts,
'domain' => 'linkbucks.com'
);
$json = json_decode(
curl(
'https://www.linkbucks.com/api/createLink/single',
NULL,
json_encode($postData)
)
);
var_dump($json);
return $json->link;
}
var_dump( bucksapi( "LINK_URL", 'API_KEY', 'USER_NAME' ) );
?>
Related
Essentially the following script is working fine when in local host but fails to load (Timeout) anytime loaded from a web server, is their something incorrectly written? I know it's not the end point api url that's the issue, since it works on local. Please see below, wondering if it's caused by curl_setopt:
$id = "dhl";
$number = "039103913";
// Parameters setting
$key = 'key';
$secret = 'scret';
$param = array (
'id' => $id,
'number' => $number,
'phone' => '',
'ship_from' => '',
'ship_to' => '',
'area_show' => 1,
'order' => 'desc'
);
// Request Json
$json = json_encode($param, JSON_UNESCAPED_UNICODE);
$signature = strtoupper(md5($json.$key.$secret));
$url = 'https://www.kd100.com/api/v1/tracking/realtime';
$headers = array (
'Content-Type:application/json',
'API-Key:'.$key,
'signature:'.$signature,
'Content-Length:'.strlen($json)
);
// Send post request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
$data = json_decode($result, true);
echo json_encode($data);
in the below example, when i am enabling post data curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
getting 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method', but when i disabled the post data, its working.
Should i pass this data parameters anywhere else?
$get_token = new GetToken();
$token_obj = $get_token->get_session_token();
$accessKeyID = $token_obj->access_key_id;
$secretAccessKey = $token_obj->secret_key;
$regionName = $token_obj->region;
$serviceName = 'execute-api';
$httpMethodName = 'POST';
$canonicalURI = '/orders/salesorder';
$queryParametes = array();
$awsHeaders = array('content-type'=>'application/json','host'=>'api.mysite.com','id_token'=>$token_obj->id_token,'x-amz-date'=>gmdate("Ymd\THis\Z"),'x-amz-security-token'=>$token_obj->session_token);
$payload = "";
$get_aws4_sign = new AWSV4($accessKeyID,$secretAccessKey,$regionName,$serviceName,$httpMethodName,$canonicalURI,$queryParametes,$awsHeaders,$payload);
$headers_result = $get_aws4_sign->getHeaders();
$headersArr = array(
'host' => $headers_result['host'],
'id_token' => $headers_result['id_token'],
'xamzdate' => $headers_result['x-amz-date'],
'xamzsecuritytoken' => $headers_result['x-amz-security-token'],
'Authorization' => $headers_result['Authorization']
);
$data = array("id" => "126757879");
$data_string = json_encode($data);
$ch = curl_init('https://api.mysite.com/orders/salesorder');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'content-type: '.$headers_result['content-type'],
'host: '.$headers_result['host'],
'id_token: '.$headers_result['id_token'],
'x-amz-date: '.$headers_result['x-amz-date'],
'x-amz-security-token: '.$headers_result['x-amz-security-token'],
'Authorization: '.$headers_result['Authorization']
));
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result = json_decode( curl_exec($ch), TRUE);
//close connection
curl_close($ch);
print_r($result);
$get_token = new GetToken();
$token_obj = $get_token->get_session_token();
$accessKeyID = $token_obj->access_key_id;
$secretAccessKey = $token_obj->secret_key;
$regionName = $token_obj->region;
$serviceName = 'execute-api';
$httpMethodName = 'POST';
$canonicalURI = '/orders/salesorder';
$queryParametes = array();
$awsHeaders = array('content-type'=>'application/json','host'=>'api.mysite.com','id_token'=>$token_obj->id_token,'x-amz-date'=>gmdate("Ymd\THis\Z"),'x-amz-security-token'=>$token_obj->session_token);
$data = array("id" => "126757879");
$data_string = json_encode($data);
$payload = $data_string;
$get_aws4_sign = new AWSV4($accessKeyID,$secretAccessKey,$regionName,$serviceName,$httpMethodName,$canonicalURI,$queryParametes,$awsHeaders,$payload);
$headers_result = $get_aws4_sign->getHeaders();
$headersArr = array(
'host' => $headers_result['host'],
'id_token' => $headers_result['id_token'],
'xamzdate' => $headers_result['x-amz-date'],
'xamzsecuritytoken' => $headers_result['x-amz-security-token'],
'Authorization' => $headers_result['Authorization']
);
$ch = curl_init('https://api.mysite.com/orders/salesorder');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'content-type: '.$headers_result['content-type'],
'host: '.$headers_result['host'],
'id_token: '.$headers_result['id_token'],
'x-amz-date: '.$headers_result['x-amz-date'],
'x-amz-security-token: '.$headers_result['x-amz-security-token'],
'Authorization: '.$headers_result['Authorization']
));
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//execute post
$result = json_decode( curl_exec($ch), TRUE);
//close connection
curl_close($ch);
print_r($result);
I can't figure out why the code below doesn't work, but it does when I replace 'page' => $page_no with 'page' => 4.
The code:
$page_no = $_GET['page_no'];
$base_url = 'url here';
$api_id = 'api here';
$secret = ' secret here ';
$postvars = [
'query' => 'query here',
'page' => $page_no,
'fields' => ['ip', 'city','province', 'country_code', 'country'],
'fattened' => true
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$base_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postvars));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$api_id:$secret");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$json = curl_exec($ch);
The URL I am using is: https://example.com/search.php?page_no=4
Any help is greatly appreciated.
Good day! I'm trying to load an image using the method appWidgets.saveAppImage. In the beginning I receive URL the server for loading -> getAppImageUploadServer, there all ok!
I receive a hash and an image, send them a POST request and get an error. Here is my code:
$token = "Service_access_key";
$tmp_image = file_get_contents('https://www.ejin.ru/wp-content/uploads/2017/12/667108931864_667108931864-150x150.jpg');
file_put_contents(dirname(__FILE__).'/tmp.jpg',$tmp_image);
$img_path = dirname(__FILE__).'/tmp.jpg';
$post_data = array("image" => "#".$img_path);
$upload_url = file_get_contents("https://api.vk.com/method/appWidgets.getAppImageUploadServer?v=5.85&image_type=50x50&access_token=".$token);
$url = json_decode($upload_url)->response->upload_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
$safe = file_get_contents("https://api.vk.com/method/appWidgets.saveAppImage?v=5.85&hash=".$result['hash']."&image=".$result['image']."&access_token=".$token);
echo $safe;
echo:
"error_code":129,"error_msg":"Invalid photo: file not found, from upl_850128?act=app_widget_image"
what's my mistake?
<?
$request_params = array(
'image_type' => '510x128',
'access_token' => 'xxx',
'v' => '5.92'
);
$t = json_decode(file_get_contents('https://api.vk.com/method/appWidgets.getAppImageUploadServer?'. http_build_query($request_params)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $t->response->upload_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("image" => new CURLFile(dirname(__FILE__).'\img.jpg')));
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
$request_params = array(
'hash' => $result->hash,
'image' => $result->image,
'access_token' => 'xxx',
'v' => '5.92'
);
print_r(file_get_contents('https://api.vk.com/method/appWidgets.saveAppImage?'. http_build_query($request_params)));
?>
i need to post multiple message to facebook wall from the mysql database. first i fetch the data from mysql and put it in while loop
while($row=mysql_fetch_array($result))
{
$des=$row[1];
$purpose=$row[3];
$price_sale=$row[4];
$price_rent=$row[5];
$img="example.com/images".mysql_result($result,0,2);
$attachment = array(
'access_token' => "$token",
'message' => $des,
'picture' => $img,
'link' => "example.com"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
echo $result;
}
the $result contain 3 records. But only post the first row. Plz give a solution for this
Try changing the name of the variable that accepts the curl output.You are using the same variable above.
while($row=mysql_fetch_array($result))
{
$des=$row[1];
$purpose=$row[3];
$price_sale=$row[4];
$price_rent=$row[5];
$img="example.com/images".mysql_result($result,0,2);
$attachment = array(
'access_token' => "$token",
'message' => $des,
'picture' => $img,
'link' => "example.com"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/xxxxxxxxxxx/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$curlresult = curl_exec($ch);
curl_close ($ch);
echo $curlresult;
}