|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Need help with X-TBA-App-Id Header for TBA API
What exactly am I supposed to put in the header when requesting?
For the FRC Events API V2.0 the header I use is "Authentication: Basic *my auth key*" What do I use for the TBA API Header? I have tried "frc3991:scouting-system:v01" and "X-TBA-App-Id: frc3991:scouting-system:v01" Neither have worked, I'm prob just missing something simple . Thanks for the help. |
|
#2
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
What you have should work just fine. Are you sure you're making the request with that header? If you're using a Web request function in a programming language, usually you have to set headers by name (something.setHeader("X-TBA-App-Id", "my:app:id") )
|
|
#3
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
this is probably very inneficient but for the FRC API i used a php method I found online
Code:
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Authorization: Basic *My Auth Key*"
)
);
$context = stream_context_create($opts);
$apiurl = "https://frc-api.firstinspires.org/v2.0/2016/matches/TXHO?tournamentLevel=qual&matchNumber=*";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
Code:
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-TBA-App-Id: frc3991:scouting-system:v01"
)
);
$context = stream_context_create($opts);
$apiurl = "www.thebluealliance.com/api/v2/team/frc3991/2016/events";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
|
|
#4
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Do you get nothing back, or a JSON-ified error message?
|
|
#5
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Something changed recently (not sure what), but sometimes you may have to send a User-Agent header string as well.
|
|
#6
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Oh hell, i forgot to http:// in fornt of the url, the code was searching for the site locally without it, thanks for the help guys
Code that works if anyone cares: Code:
<?php
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"X-TBA-App-Id: frc3991:scouting-system:v01"
)
);
$context = stream_context_create($opts);
$apiurl = "http://www.thebluealliance.com/api/v2/team/frc3991/2016/events";
$file = file_get_contents($apiurl, false, $context);
echo $file;
?>
|
|
#7
|
|||||
|
|||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
That's a very... "PHP" way of handling a lack of protocol, lol! Glad you got it all figured out.
|
|
#8
|
|||||
|
|||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
I'm pretty sure this is caused by CloudFlare somehow (it's DDON protection might automatically stop requests that come from scripts). It's difficult to trace because it only seems to happen sometimes.
|
|
#9
|
|||
|
|||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Hi, I had this same problem a while ago, where it would give me error 403, forbidden.
I found that I had to add a header called 'User-Agent' with "Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11)Gecko/20071127 Firefox/2.0.0.11" to make it think it was a web browser and wouldn't get blocked. My code for my (python) thingy is https://github.com/Cabey4/4613-Auto-Scout but it looks like you've already sorted it. But if anyone else gets a 403 forbidden error with the TBA/The Blue Alliance api that's probably why. |
|
#10
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Quote:
Code:
pip install requests |
|
#11
|
|||
|
|||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Really, it is the fact that PHP even lets you use "file_get_contents()" to make HTTP requests. "file_get_contents()" is better suited for local files, and CURL or something more elegant that probably wraps CURL for remote HTTP requests.
|
|
#12
|
|||||
|
|||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Quote:
|
|
#13
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
Quote:
|
|
#14
|
||||
|
||||
|
Re: Need help with X-TBA-App-Id Header for TBA API
I am also currently using file_get_contents() mostly because I am only ever fetching a JSON array once (and it's only needed to set up a MySQL database once per event for scouting) but how I am forming it is
Code:
$jsonurl = "http://www.thebluealliance.com/api/v2/event/$eventcode/teams?X-TBA-App-Id=frc2557:pnwscout:v01" or in your case $jsonurl = "http://www.thebluealliance.com/api/v2/team/frc3991/2016/events?X-TBA-App-Id=frc3991:scouting-system:v01 |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|