Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   General Forum (http://www.chiefdelphi.com/forums/forumdisplay.php?f=16)
-   -   Need help with X-TBA-App-Id Header for TBA API (http://www.chiefdelphi.com/forums/showthread.php?t=148679)

dirtbikerxz 28-05-2016 12:33

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 :P. Thanks for the help.

Jaci 28-05-2016 12:56

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") )

dirtbikerxz 28-05-2016 13:09

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;
?>

That works so I tried to do the same thing with the TBA Api

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;

?>

but I get nothing back... (also tried only frc3991:scouting-system:v01 without the X-TBA-App-Id: portion in the header, didn't work)

Jaci 28-05-2016 13:19

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by dirtbikerxz (Post 1590010)
this is probably very inneficient but for the FRC API i used a php method I found online

but I get nothing back... (also tried only frc3991:scouting-system:v01 without the X-TBA-App-Id: portion in the header, didn't work)

Do you get nothing back, or a JSON-ified error message?

Michael Hill 28-05-2016 13:20

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.

dirtbikerxz 28-05-2016 13:52

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;

?>


synth3tk 28-05-2016 14:00

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.

plnyyanks 28-05-2016 14:12

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by Michael Hill (Post 1590012)
Something changed recently (not sure what), but sometimes you may have to send a User-Agent header string as well.

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.

Cabey4 28-05-2016 18:48

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.

jtrv 28-05-2016 19:04

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by Cabey4 (Post 1590040)
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.

You can make things a hell of a lot simpler with the requests library. Just make sure you do
Code:

pip install requests
to install it and suddenly you've made everything loads easier (example).

maths222 29-05-2016 11:53

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by synth3tk (Post 1590016)
That's a very... "PHP" way of handling a lack of protocol, lol! Glad you got it all figured out.

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.

synth3tk 29-05-2016 14:12

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by maths222 (Post 1590091)
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.

I didn't even catch that, thanks. I'm assuming that they have some reason for using file_get_contents. If not, OP, you should look into CURL.

dirtbikerxz 29-05-2016 14:16

Re: Need help with X-TBA-App-Id Header for TBA API
 
Quote:

Originally Posted by synth3tk (Post 1590100)
I didn't even catch that, thanks. I'm assuming that they have some reason for using file_get_contents. If not, OP, you should look into CURL.

Ya, I was only using file_get_contents because I already knew how, but I will look into CURL thanks!

Oscar Lewis 29-05-2016 14:52

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

Glad you got it all sorted out!


All times are GMT -5. The time now is 04:56.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi