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:
save the API key in a .txt file (just paste the key on the first line, then press Enter, but leave the second line blank)
use code of this form for your R to recognize your API key:
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!
@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:
If you get the following warning message, check that you pressed enter after the API key line so there is a second (blank) line:
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!