Not Able to Get Data From Unocoin Public API - php

I am using cURL to get data from this link of Unocoing - https://www.unocoin.com/trade?all
function api_price($api_url){
if(!empty($api_url)){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $api_url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
return $response;
curl_close($curl);
}
}
if(!empty($_GET['url'])){
$api_url=$_GET['url'];
$tag=$_GET['tag'];
$api_price=api_price($api_url);
$response = json_decode($api_price, true);
$output= $response[$tag];
echo $output['lastPrice'];
}
I am using same code for other exchanges. But some like unocoin, coindelta show bool(false)
https://coindelta.com/api/v1/public/getticker/

Related

PHP API request

can anyone help with an API
I having an API that should get parameters in
https://app.wappapi.in/api/send.php?number=9198480xxxxx&type=text&message=test-message&instance_id=609ACF283XXXX&access_token=e10adcxxxxba59axxx56e0xxxxxxxxxx
in post method
the question is if I send it like using this god will it get it like needed?
<?php
$curl = curl_init();
$number=$_POST['type'];
$message=$_POST['type'];
$id=$_POST['type'];
$token=$_POST['type'];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.wappapi.in/api/send.php",
CURLOPT_POSTFIELDS => "number={$number}type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST"));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Don't use CURLOPT_POSTFIELDS, because the query parameters come with the URI
Instead:
CURLOPT_URL => "https://app.wappapi.in/api/send.php?number={$number}"
."&type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_POST => 1
Hope it solved your problem.

Curl not executing in php on server

I have this function to send message
Code:
public static function send($mobile,$otp,$country_code){
$message = "Your 2-way authentication OTP is $otp";
$curl = curl_init();
$authKey = App::environment('MSGAUTH');
$senderId = App::environment('SENDERID');
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.XXX.com/api/sendhttp.php?authkey=".$authKey."&mobiles=".$mobile."&country=$country_code&sender=".$senderId."&route=3&message=$message",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return false;
} else {
return true;
}
}
Issue is i'm getting blank quotes in the error part and this code is working on my local system but on server control is going in the else part. When i print $err i get this output
Any solution to resolve this issue.
Thanks

How to get json from instagram.com/user/?__a=1

I am using curl with postman to get a json from an Instagram user through this URL "https://www.instagram.com/kiddothegame/?__a=1".
It works and postman shows me a json response with info like:
{"seo_category_infos":[["Beauty","beauty"],["Dance & Performance","dance_and_performance"],["Fitness","fitness"],["Food & Drink","food_and_drink"],["Home & Garden","home_and_garden"],["Music","music"],["Visual Arts","visual_arts"]],.....
Now I try to do the same request with PHP:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://www.instagram.com/kiddothegame/?__a=1',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
And the echo result is :
string(52678) "
"
Oddly all the characters are spaces.
What am I missing?

Having an issue with cURL (PHP)

So I have a licensing system that has an API with it, though I barely understand cURL. Could someone please explain what I did wrong?
Most of this code was pulled off of the documentation for the API I'm using.
Here is the code within my PHP login page.
function checkLicense() {
$curl = curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/", $licensekey ,"?consumer_key=", $consumer_key ,"&consumer_secret=", $consumer_secret ,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #: " . $err;
} else {
return $response;
}
}
Error:
cURL Error #: Could not resolve proxy: ?consumer_key=
Edit: When I visit the link using a license key from the database in the spot "$licensekey" and filling in the other two variables it returns the json I want.
The URL it should look like to get the json:
https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/license-key-example?consumer_key=key-example&consumer_secret=secret-example
Here is the json it returns
{"success":true,"data":{"id":"5","orderId":null,"productId":null,"licenseKey":"hidden-for-privacy","expiresAt":null,"validFor":"0","source":"2","status":"3","timesActivated":null,"timesActivatedMax":"0","createdAt":"2019-11-07 01:43:16","createdBy":"1","updatedAt":null,"updatedBy":null}}
Edit 2:
I have changed , to .
$consumer_key = "hidden-for-privacy";
$consumer_secret = "hidden-for-privacy";
$licensekey = $_SESSION['key'];
function checkLicense() {
$curl = curl_init();
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.scriptic.xyz/wp-json/lmfwc/v2/licenses/". $licensekey ."?consumer_key=". $consumer_key ."&consumer_secret=". $consumer_secret,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
return $response;
}
}
New Error:
{"code":"lmfwc_rest_authentication_error","message":"Consumer key or secret is missing.","data":{"status":401}}
Ok the issue is solved thank you to everyone who helped. I moved the variables inside the function and now it's returning what I want.

PHP Request for Grafana API Returning Error

I am making a request for api chart to be automatically redirected, without password, after redirection, receive the following alert:
SCRIPT
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "3000",
CURLOPT_URL => "http://localhost:3000/d/BSFmuV5Zz/dash?orgId=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer api-key-here"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "CURL Error #:" . $err; ?>
<?php } else {
echo $response;
}
?>
Operating System: Windows
Download Link: https://grafana.com/grafana/download?platform=windows

Categories