OCCRA
Go to Post If it reads MINUS voltage, the power is reversed (and this is bad). - DonRotolo [more]
Home
Go Back   Chief Delphi > Competition > Rules/Strategy > Scouting
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #16   Spotlight this post!  
Unread 11-20-2017, 08:17 PM
liammaloney00 liammaloney00 is offline
Registered User
FRC #3357 (COMETS)
Team Role: Driver
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Michigan
Posts: 13
liammaloney00 is an unknown quantity at this point
Re: Blue Alliance API V3 - Java Auth Key Issue

Yes, the link works, I can access the API on Google Chrome, but I am forbidden in Java.
Reply With Quote
  #17   Spotlight this post!  
Unread 11-20-2017, 08:20 PM
liammaloney00 liammaloney00 is offline
Registered User
FRC #3357 (COMETS)
Team Role: Driver
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Michigan
Posts: 13
liammaloney00 is an unknown quantity at this point
Re: Blue Alliance API V3 - Java Auth Key Issue

Yes, the link works for me on Google Chrome, but I am still forbidden in Java. Can you just put the Auth Key in the url like the link has it? Or is using .setRequestProperty() correct?
Reply With Quote
  #18   Spotlight this post!  
Unread 11-20-2017, 08:45 PM
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
no team (The Blue Alliance)
Team Role: Engineer
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC
Posts: 1,202
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Your code seems correct, I just ran it on my own and it worked for me.

Code:
import java.net.*;
import java.io.*;

public class APIRequest {

    public static String APIRead(String extension) throws Exception {

        StringBuilder result = new StringBuilder();

        URL theBA = new URL("https://www.thebluealliance.com/api/v3/" + extension);
        HttpURLConnection con = (HttpURLConnection) theBA.openConnection();
        con.setRequestMethod("GET");
        con.addRequestProperty("X-TBA-Auth-Key", "zxkl7V7cuY5U8nJyBU9wYbzID8LL177rFM3f05V8aSCcobi5Y2CGEnSYaDocN9ok");

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

        String response;
        while ((response = in.readLine()) != null) {
            result.append(response);
        }
        
        in.close();
        return result.toString();
    }
    
    public static void main(String[] args) throws Exception {
        System.out.println(APIRead("team/frc254"));
    }
}
I ran:

Code:
$ javac APIRequest.java  && java APIRequest 
{  "address": null,   "city": "San Jose",   "country": "USA",   "gmaps_place_id": null,   "gmaps_url": null,   "home_championship": {    "2017": "Houston",     "2018": "Houston"  },   "key": "frc254",   "lat": null,   "lng": null,   "location_name": null,   "motto": "Delicious and nutritious!",   "name": "NASA/NASA Ames Research Center/Apple/Google/Innovation First International/Analog Devices/AMEX Plating/BAE Systems/The Wong Family/Brin Wojcicki Foundation/Lockheed Martin/West Coast Products/Qualcomm/Intuitive Surgical/Cisco/Gilbert Spray Coat/Applied Welding/Dropbox/Orange Vise Company/Four-D Metal Finishing/Vivid-Hosting & Bellarmine College Preparatory",   "nickname": "The Cheesy Poofs",   "postal_code": "95126-1215",   "rookie_year": 1999,   "state_prov": "California",   "team_number": 254,   "website": "https://www.team254.com"}
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
The Blue Alliance | The Blue Alliance for Android | FRC Notebook
Reply With Quote
  #19   Spotlight this post!  
Unread 11-20-2017, 08:56 PM
liammaloney00 liammaloney00 is offline
Registered User
FRC #3357 (COMETS)
Team Role: Driver
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Michigan
Posts: 13
liammaloney00 is an unknown quantity at this point
Re: Blue Alliance API V3 - Java Auth Key Issue

How are you running the code? I copied and pasted this code into Eclipse Oxygen and still get the 403 error.
Reply With Quote
  #20   Spotlight this post!  
Unread 11-20-2017, 09:29 PM
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
no team (The Blue Alliance)
Team Role: Engineer
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC
Posts: 1,202
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by liammaloney00 View Post
How are you running the code? I copied and pasted this code into Eclipse Oxygen and still get the 403 error.
I ran it in a fresh docker container running ubuntu + java 9.

I can help debug your issue better if you can show the body of the response from TBA. For example, if you pass an invalid auth key, you will see something like this returned:

Code:
{"Error": "X-TBA-Auth-Key is invalid. Please get an access key at http://www.thebluealliance.com/account."}
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
The Blue Alliance | The Blue Alliance for Android | FRC Notebook
Reply With Quote
  #21   Spotlight this post!  
Unread 11-20-2017, 09:40 PM
liammaloney00 liammaloney00 is offline
Registered User
FRC #3357 (COMETS)
Team Role: Driver
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Michigan
Posts: 13
liammaloney00 is an unknown quantity at this point
Re: Blue Alliance API V3 - Java Auth Key Issue

I have tried running the code from both the Eclipse console and Windows Command Prompt. Both return the same 403 error even with an invalid auth key.


Here is the exact error:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.thebluealliance.com/api/v3/team/frc254
at sun.net.www.protocol.http.HttpURLConnection.getInp utStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInp utStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl. getInputStream(Unknown Source)
at test.APIRequest.APIRead(APIRequest.java:16)
at test.APIRequest.main(APIRequest.java:28)

I'm not getting anything from TBA. How can view TBA's response?
Reply With Quote
  #22   Spotlight this post!  
Unread 11-21-2017, 08:25 AM
liammaloney00 liammaloney00 is offline
Registered User
FRC #3357 (COMETS)
Team Role: Driver
 
Join Date: Jan 2017
Rookie Year: 2015
Location: Michigan
Posts: 13
liammaloney00 is an unknown quantity at this point
Re: Blue Alliance API V3 - Java Auth Key Issue

I got it!!!! I found that if you include a line setting a web browser and user before the key line, you get access:
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
Reply With Quote
  #23   Spotlight this post!  
Unread 11-21-2017, 09:08 AM
bdaroz's Avatar
bdaroz bdaroz is online now
Programming Mentor
AKA: Brian Rozmierski
FRC #5881 (TVHS Dragons)
Team Role: Mentor
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Albany, NY
Posts: 612
bdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by liammaloney00 View Post
I got it!!!! I found that if you include a line setting a web browser and user before the key line, you get access:
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
The 403 must have been from Cloudflare.
Reply With Quote
  #24   Spotlight this post!  
Unread 11-21-2017, 09:49 AM
Eugene Fang's Avatar
Eugene Fang Eugene Fang is offline
The Blue Alliance
no team
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Bay Area, CA -> Pittsburgh, PA
Posts: 925
Eugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by bdaroz View Post
The 403 must have been from Cloudflare.
Hmm we should add that to our documentation.

liammaloney00, can you try setting User-Agent to something else (like "Team XXX super mega scouting app") and seeing if that works?
__________________
Eugene Fang
2010 Silicon Valley Regional Dean's List Finalist

Various FLL Teams - Student (2000-2006), Mentor (2007-2010)
FRC Team 604 - Student (2007-2010), Mentor/Remote Advisor (2011-Present)
FRC Team 1323 - Mentor/Remote Advisor (2011-2014)

The Blue Alliance | TBA GameDay | TBA Android App | TBA Blog
Reply With Quote
  #25   Spotlight this post!  
Unread 11-21-2017, 03:29 PM
bdaroz's Avatar
bdaroz bdaroz is online now
Programming Mentor
AKA: Brian Rozmierski
FRC #5881 (TVHS Dragons)
Team Role: Mentor
 
Join Date: Jan 2016
Rookie Year: 2016
Location: Albany, NY
Posts: 612
bdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond reputebdaroz has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by Eugene Fang View Post
Hmm we should add that to our documentation.

liammaloney00, can you try setting User-Agent to something else (like "Team XXX super mega scouting app") and seeing if that works?
Just an aside - this also explains why it worked for Phil w/ the same code. Their heuristics already knew Phil's IP and probably didn't apply as many "rules" to the connection. I've seen this before working with sites thru cloudflare. It'll work on my computer at home, but deployed in a datacenter it chokes on a 403.

I'm pretty sure a browser-like User-Agent string is required to pass it's muster.
Reply With Quote
  #26   Spotlight this post!  
Unread 11-21-2017, 04:23 PM
plnyyanks's Avatar
plnyyanks plnyyanks is offline
Data wins arguments.
AKA: Phil Lopreiato
no team (The Blue Alliance)
Team Role: Engineer
 
Join Date: Apr 2010
Rookie Year: 2010
Location: NYC
Posts: 1,202
plnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond reputeplnyyanks has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by bdaroz View Post
Just an aside - this also explains why it worked for Phil w/ the same code. Their heuristics already knew Phil's IP and probably didn't apply as many "rules" to the connection. I've seen this before working with sites thru cloudflare. It'll work on my computer at home, but deployed in a datacenter it chokes on a 403.

I'm pretty sure a browser-like User-Agent string is required to pass it's muster.
Interestingly, I was running it on c9.io last night (fastest way I could get a clean environment), not my local machine.
__________________
Phil Lopreiato - "It's a hardware problem"
Team 1124 (2010 - 2013), Team 1418 (2014), Team 2900 (2016)
The Blue Alliance | The Blue Alliance for Android | FRC Notebook
Reply With Quote
  #27   Spotlight this post!  
Unread 11-21-2017, 04:45 PM
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 4,438
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by Eugene Fang View Post
Hmm we should add that to our documentation.

liammaloney00, can you try setting User-Agent to something else (like "Team XXX super mega scouting app") and seeing if that works?
I just did a test with my own java API interface... when I set it up originally I set the User-Agent to "TBA-API" and its worked just fine. I removed that, and got a 403. So it seems the content doesn't really matter, it just has to be there.
__________________
2007 - Present: Mentor, 2177 The Robettes
LRI: North Star 2012-2016; Lake Superior 2013-2014; MN State Tournament 2013-2014, 2016-2018; Galileo 2016; Iowa 2017; Tesla 2017; Northern Lights 2018
2015: North Star Regional Volunteer of the Year
2016: Lake Superior WFFA
Reply With Quote
  #28   Spotlight this post!  
Unread 11-21-2017, 05:02 PM
Eugene Fang's Avatar
Eugene Fang Eugene Fang is offline
The Blue Alliance
no team
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Bay Area, CA -> Pittsburgh, PA
Posts: 925
Eugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond reputeEugene Fang has a reputation beyond repute
Re: Blue Alliance API V3 - Java Auth Key Issue

Quote:
Originally Posted by Jon Stratis View Post
I just did a test with my own java API interface... when I set it up originally I set the User-Agent to "TBA-API" and its worked just fine. I removed that, and got a 403. So it seems the content doesn't really matter, it just has to be there.
Good to know. I'll update the docs to reflect that.
__________________
Eugene Fang
2010 Silicon Valley Regional Dean's List Finalist

Various FLL Teams - Student (2000-2006), Mentor (2007-2010)
FRC Team 604 - Student (2007-2010), Mentor/Remote Advisor (2011-Present)
FRC Team 1323 - Mentor/Remote Advisor (2011-2014)

The Blue Alliance | TBA GameDay | TBA Android App | TBA Blog
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:14 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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