PHP - Fortnite API show me "Invalid authentication credentials"? - php

I would like to make a small Fortnite API, but I always get an error in the JSON file.
{"message":"Invalid authentication credentials"}
My PHP Code:
$ch = curl_init();
//pc, xbl, psn
curl_setopt($ch, CURLOPT_URL, "https://api.fortnitetracker.com/v1/profile/pc/MyName");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'TRN-Api-Key: My-API-Code'
));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
$fp = fopen("myStats.json", "w");
fwrite($fp, $response);
fclose($fp);
$data = json_decode(file_get_contents("myStats.json"));
$solo = $data->stats->p2;//solos data
$duos = $data->stats->p10;//duos data
$squads = $data->stats->p9;//squads data
$matches = $data->recentMatches;//match data
$sesh1 = $matches[0]->id->valueInt;
$solo_wins = $solo->top1->valueInt;
$duos_wins = $duos->top1->valueInt;
$squads_wins = $squads->top1->valueInt;
$solo_matches = $solo->matches->valueInt;
$duos_matches = $duos->matches->valueInt;
$squads_matches = $squads->matches->valueInt;
$solo_kd = $solo->kd->valueDec;
$duos_kd = $duos->kd->valueDec;
$squads_kd = $squads->kd->valueDec;
$solo_games = $solo->matches->valueInt;
$duos_games = $duos->matches->valueInt;
$squads_games = $squads->matches->valueInt;
$solo_kills = $solo->kills->valueInt;
$duos_kills = $duos->kills->valueInt;
$squads_kills = $squads->kills->valueInt;
$total_matches = ($solo_matches+$duos_matches+$squads_matches);
$total_wins = ($solo_wins+$duos_wins+$squads_wins);
$total_kills = ($solo_kills+$duos_kills+$squads_kills);
$total_kd = (round($total_kills/($total_matches-$total_wins),2));
echo 'Total Matches: '.$total_matches.'<br>';
echo 'Total Wins: '.$total_wins.'<br>';
echo 'Total Kills: '.$total_kills.'<br>';
echo 'Total KD: '.$total_kd.'<br>';
echo $sesh1;
?>
I entered the correct API code. Why is this message written in a JSON file and not my wins? It's so crazy because it should work.

What returns on line 11? You are using var_dump($response);
Could you write die(); under that line and provide us the return that it gives?
There might be something wrong on how you handle the headers. I can't check for sure right now as I am not home. But I might be able to test this out later.

Related

CloudSight Response Speed

I am experimenting with the Cloudsight API (Image recognition) and am seeing speed issues in response time. Their website advertises a 6-12 second response time, but I am routinely seeing responses taking up to and well over 20 seconds.
I would like to know if this is something on CloudSights end and that is just the response time, or if my code is causing these delays by being unoptimized or doing unnecessary work.
The following is my PHP code, it works fully, I can upload an image and read/display the response. My HTML code is a simple form that calls this PHP file.
<?php
$filename = $_FILES['fileToUpload']['name'];
$filedata = $_FILES['fileToUpload']['tmp_name'];
$filesize = $_FILES['fileToUpload']['size'];
$filetype = $_FILES['fileToUpload']['type'];
/*$tmpfile = $_FILES['fileToUpload']['tmp_name'];
$filename = basename($_FILES['fileToUpload']['name']);*/
$ch = curl_init("https://api.cloudsightapi.com/image_requests");
//$ch = curl_init("http://requestb.in/131zwlo1");
$postFields = [
"image_request[locale]" => "en-US",
"image_request[language]" => "en-US",
"image_request[image]" => "#$filedata".";filename=#$filename".";type=#$filetype"
];
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: CloudSight [key]", "Content-Type:multipart/form-data"));
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result, true);
$token = $result['token'];
$status = $result['status'];
sleep(3);
while($status == "not completed"){
sleep(1);
$cht = curl_init("http://api.cloudsightapi.com/image_responses/$token");
curl_setopt($cht, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cht, CURLOPT_HTTPHEADER, array("Authorization: CloudSight 6-j8FTD-h1ZtnlYgacdSEQ"));
$result = curl_exec($cht);
curl_close($cht);
$result = json_decode($result, true);
$status = $result['status'];
};
$name = $result['name'];
$reason = $result['reason'];
if($name != ""){
echo "\nName: $name";
};
if($reason != ""){
echo "\nReason Skipped: $reason";
};
?>

how to post the value in url using PHP

I am creating a web service. I have tried to write an URL but its throwing error. I am not getting where I am going wrong. I want to pass these variable values in url and depending on this i want to call the web service
<?php
if($_POST["occupation"] == '1'){
$occupation = 'Salaried';
}
else{
$occupation = 'Self+Employed';
}
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?interestRateType='.$_POST["interestRateType"]'.&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&age='.$_POST["age"];
echo $url;
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
$json = json_decode($result, true);
//print_r($json);
//echo $json['resultList']['interestRateMin'];
$json_array = $json['resultList'];
print_r($json_array);
?>
Try below code. You have syntax error before &occupation
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?interestRateType='.$_POST["interestRateType"].'&occupation='.$_POST["occupation"].'&offeringTypeId='.$_POST["offeringID"].'&city='.$_POST["city"].'&loanAmt='.$_POST["loanAmt"].'&age='.$_POST["age"];
Copy this because there is some ' and . error
$url = 'http://www.aaa.com/ajaxv2/getCompareResults.html?
interestRateType='.$_POST["interestRateType"].'&
occupation='.$_POST["occupation"].'&
offeringTypeId='.$_POST["offeringID"].'&
city='.$_POST["city"].'&
loanAmt='.$_POST["loanAmt"].'&
age='.$_POST["age"];

Get more than 10 results by google search API in php

I am trying to get 10 pages result listed using the following cod below. When i run the URL directly i get a json string but using this in code it does not returns anything. Please tell me where i am doing wrong.
$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=CompTIA A+ Complete Study Guide Authorized Courseware site:.edu&start=20";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body,true);
print_r($json);
Now i am using the following code but it outputs only four entries of a page. Please tell me where i am doing wrong.
$term = "CompTIA A+ Training Kit Microsoft Press Training Kit";
for($i=0;$i<=90;$i+=10)
{
$term = $val.' site:.edu';
$query = urlencode($term);
$url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' . $query . '&start='.$i;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body,true);
//print_r($json);
foreach($json['responseData']['results'] as $data)
{
echo '<tr><td>'.$i.'</td><td>'.$url.'</td><td>'.$k.'</td><td>'.$val.'</td><td>'.$data['visibleUrl'].'</td><td>'.$data['unescapedUrl'].'</td><td>'.$data['content'].'</td></tr>';
}
}
Just try with urlencode
$query = urlencode('CompTIA A+ Complete Study Guide Authorized Courseware site:.edu');
$url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=' . $query . '&start=20';

Sending post data via curl using php

I am having problem in this script. The problem i m facing is when i send a large amount of data in a variable like cc_no = 3654785698568 i get blank on text file where i m checking it. Others variables are working fine.
session_set_cookie_params(0);
session_start();
echo $cc_name = $_SESSION['card_name'];
echo $cc_no = $_SESSION['card_no'];
echo $cc_cvv2 = $_SESSION['cvv2'];
echo $cc_expiry = $_SESSION['expiry'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/db/get.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"cc_name=$cc_name&cc_no=$cc_no&cc_cvv2=$cc_cvv2&cc_expiry=$cc_expiry");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
The code which is catching the values on other server.
<?php
$fp = fopen("formdata.txt", "a");
$cc_name1 = $_POST['cc_name'];
$cc_no1 = $_POST['card_no'];
$cc_cvv21 = $_POST['cc_cvv2'];
$cc_expiry1 = $_POST['cc_expiry'];
$data = "$cc_name1 | $cc_no1 | $cc_cvv21 | $cc_expiry1 \n";
fwrite($fp, $data);
fclose($fp);
?>
$cc_no1 = $_POST['card_no'];
should be:
$cc_no1 = $_POST['cc_no'];
Edit:
I really hope this is for learning only. CCs should not be handled this way, especially over standard http.

output XML from Yahoo BOSS API with PHP

I managed to get this code so far:
<?php
//Gather data and prepare query
$thequery = urlencode($_GET['s']);
$yhost = 'http://boss.yahooapis.com';
$apikey = 'xxxxxxxxxxxxxxx';
$url = $yhost.'/ysearch/news/v1/'.$thequery.'?appid='.$apikey.'&format=xml';
//Get the results
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$results = new SimpleXmlElement($data, LIBXML_NOCDATA);
//echo the results
foreach ($results->resultset_news->result as $theresult) {
echo ''.$theresult->title.'<br/>';
echo $theresult->abstract.'<br/>';
echo '<small><i>'.$theresult->dispurl.'</i></small><br/>';
echo '<br/><br/>';
}
So how exactly do i output actual XML rather than HTML?
Tried this:
echo $results->asXML();
?

Categories