stat231-f20 / Blog-Red-Bull

Repository for PUG Blog Project – Red Bull
https://stat231-f20.github.io/Blog-Red-Bull/
0 stars 1 forks source link

Keeping your API key confidential #2

Open katcorr opened 3 years ago

katcorr commented 3 years ago

@John-K408 @mpitts23 @jackdove23

Hi Team,

When using APIs and API keys, it's good practice to keep the key confidential, which means you don't want the actual key to show in your code. A good workflow is to:

path_in <- "YOUR PATH HERE"
key <- readLines(paste0(path_in,"/api_key_twitter.txt"))

If you get the following warning message, check that you pressed enter after the API key line so there is a second (blank) line:

Warning message:
In readLines(paste0(path_in, "/api_key_twitter.txt")) :
incomplete final line found on '..../api_key_twitter.txt'

Since your API key should be kept confidential, the file that contains the key (e.g., "api_key_twitter.txt") should NOT be pushed to the GitHub repo (which in publicly available). If you each have a consistent name for the .txt file, then the same code should work regardless of what the actual API key is, e.g. all have a file on your local machine called "api_key_twitter.txt" and then run:

readLines("api_key_twitter.txt")

You don't want others using your API key, so if someone doesn't have their own, then it won't work and that's how it should be. (I know this may seem contradictory to reproducibility, but it is still considered reproducible so long as a user has the correct permissions, i.e. their own API key).

Please let me know if you have questions regarding working with API keys!