Re: [massdotdev] Using API Key

100 views
Skip to first unread message

Tom Morris

unread,
Mar 27, 2023, 7:34:52 PM3/27/23
to massdotd...@googlegroups.com
On Mon, Mar 27, 2023 at 9:52 AM Masakazu Yasumoto
<myasu...@outlook.com> wrote:

> I'm a CS student and new to the V3 API. I'm struggling to use the API key provided. When I make an API request, where do I specify the API key? Is it included in the url? I tried something like:
> https://api-v3.mbta.com/stops&api_key=my_api_key
>
> But it didn't work. I'm creating an Android mobile application using Java. I can access the API without the key but I would like to make more than 20 calls a minute.
>
> I'm using JSONObjectRequest and StringRequest class

The separator for the query string is a question mark (?) not an
ampersand (&), so you probably want
https://api-v3.mbta.com/stops?api_key=my_api_key but most client API
libraries for HTTP have support for marshalling query strings from a
map, so if the Android one does, you should use that and let it take
care of all the punctuation, escaping, and string concatenation for
you.

Tom

Alex Morgan

unread,
Mar 27, 2023, 7:40:05 PM3/27/23
to massdotd...@googlegroups.com
What has worked for me is to add an X-API-Key header to the request. Here's something from StackOverflow on how to add headers to your requests using Volley: https://stackoverflow.com/a/35232119

Hope this helps,
Alex

On Mon, Mar 27, 2023 at 9:52 AM Masakazu Yasumoto <myasu...@outlook.com> wrote:
Hello, 

I'm a CS student and new to the V3 API. I'm struggling to use the API key provided. When I make an API request, where do I specify the API key? Is it included in the url? I tried something like: 

But it didn't work. I'm creating an Android mobile application using Java. I can access the API without the key but I would like to make more than 20 calls a minute. 

I'm using JSONObjectRequest and StringRequest class

Thank you, 

Masa

--
You received this message because you are subscribed to the Google Groups "MBTA Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to massdotdevelop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/massdotdevelopers/70e87108-dc67-432b-aa9d-fd2e1dd0eeecn%40googlegroups.com.


--
"Do the best you can until you know better. Then when you know better, do better."
Maya Angelou

Tom Connors

unread,
Mar 27, 2023, 11:45:45 PM3/27/23
to massdotd...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages