Skip to content

Instantly share code, notes, and snippets.

@christopheranderton
Last active January 2, 2024 13:07
Show Gist options
  • Save christopheranderton/8644743 to your computer and use it in GitHub Desktop.
Save christopheranderton/8644743 to your computer and use it in GitHub Desktop.
Set your Github API Token If you hit a ”GitHub API rate limit exceeded” when searching with Homebrew (http://brew.sh/).

Description

PLEASE SCROLL DOWN AND READ THE COMMENTS FOR A MORE UP TO DATE WAY (AND EASIER) TO DO THIS
When using Homebrew (http://brew.sh) and searching formulas or pull requests you may get the dreaded error message: Github API Rate limit exceeded

Let's fix that! (yeah!)


Short version

PLEASE SCROLL DOWN AND READ THE COMMENTS FOR A MORE UP TO DATE WAY (AND EASIER) TO DO THIS
Create a new Personal Token in your Github Account Settings (Sidebar: Applications) and then copy the Token. In the Terminal, use export HOMEBREW_GITHUB_API_TOKEN=YOURAPITOKENWITHFUNKYNUMBERSHERE (change that to your API Token) or add that to your .zshrc and then do source .zshrc (Catalina)

(Pre Catalina or using sill using BASH) .bash_profile and then do source .bash_profile

Step 1 - Create a Personal Access Token for Homebrew

  • Login to your Github Account or create one if you don't have one yet.
  • In the top menu to the right, click the tools icon (Account Settings).
  • Click on “Applications” in the sidebar (to the left).
  • In the box with the title “Personal Access Tokens”, press the “Create new token” button.

Note: As @rrotter mentions in the comments. ”UNCHECK EVERY SCOPE BOX when creating this token. There is no reason this token needs access to private information (unless you are developing brew casks in a private repo, but that's another issue)”. Credits to @rrotter

  • In the next box (Create a new Personal Access Token) set the name of your Token (i used homebrew but you can use anything you want). Press “Create Token”.
  • When done, you will see your token we just created in the “Personal Access Tokens” box. Copy the Token by select the token or click the copy icon to the right of the Token text.
  • The Token text should look something like this: 9927d2878ffa105fc5236c762f2fd7zfd28b841d (not a real token, just an example)

IMPORTANT! Remember To Keep The Token Safe As It Works As A “Password” For Your Github Account.

Step 2 - Set the Github API Token for Homebrew in the Terminal

  1. Fire up your Terminal.app (or iTerm.app)
  2. Use the command export HOMEBREW_GITHUB_API_TOKEN=9927d2878ffa105fc5236c762f2fd7zfd28b841d (but use your own API Token, and not the fake example one that don't work) and press enter.
  3. It's now set, however, instead of repating this every session, let's add this to our .bash_profile (if you don't know about this, see this link.)
  4. Open your .zshrc (or: .bash_profile if still using) in your favorite text editor (in this case, we use Nano in the Terminal). Make sure that you are in your Home directory (if unsure, use cd $HOME and press enter).
  5. Add the exact same line as in step 2. Press ctrl + o (to save) and then ctrl + x (to quit Nano)
  6. In your Terminal, do the command source .zshrc (loads the changes in the .zshrc file to the active session) (or source .bash_profile if still using, or on pre Catalina OS)
  7. Well, that's it!

###Helpful links


Tags: homebrew, brew, github api, token, api token, terminal, mac os x

@rrotter
Copy link

rrotter commented Apr 6, 2015

Please add to this that you should UNCHECK EVERY SCOPE BOX when creating this token. There is no reason this token needs access to private information (unless you are developing brew casks in a private repo, but that's another issue).

@warpedgeoid
Copy link

You should probably keep the public repo access scope.

@shpoont
Copy link

shpoont commented Aug 6, 2015

@rrotter is right, you don't need any permissions for the token.

@christopheranderton
Copy link
Author

Thanks @rrotter, haven't seen the comments here (must have changed the notification settings). Added your comment to the Gist.

@dgentry
Copy link

dgentry commented Oct 17, 2015

In addition to "Remember to keep the Token Safe" (which may not mean much to someone unfamiliar with OAuth tokens) you might explicitly suggest that if you publicly check in your .bash_profile or .bashrc (as many people do), that the token instead go in a separate, not-checked-in config file. This works for me:

In the file ~/.not-public:
export HOMEBREW_GITHUB_API_TOKEN=9927d2878ffakefakefake762f2fd7zfd28b841d

I do not check that file into a public repo, and keep its permissions u+rw, go-a (600).

In my .bashrc:

if [ -r ~/.not-public ]
then
    source ~/.not-public
fi

@ryanzzff
Copy link

You can simply Step 2 into:

echo "export HOMEBREW_GITHUB_API_TOKEN=9927d2878ffa105fc5236c762f2fd7zfd28b841d" >> ~/.bash_profile
. ~/.bash_profile

@NitinBag0riya
Copy link

Thanks :) Its works

@piermarcobarbe
Copy link

The 4 itemized steps right under "Step 1" section should be revised. Now creating a token requires a step less.

@PilotatHeart
Copy link

PilotatHeart commented May 19, 2016

UPDATE--Problem solved - See bottom of post for resolution. I decided to leave this post in case others have similar issues (let me know if it isn't useful and I will delete)

Original Post
Wow. I just wanted to migrate from Baseflight, to Cleanflight to make use of the 'Autotune' function. This seems SO complicated! Here is what I have done so far.. any assistance would be greatly appreciated.

  1. Opened Cleanflight, plugged in Naze 32 board (running Baseflight), in the firmware flasher made sure that "full chip erase" was checked, chose the most recent stable firmware (1.12.1 NAZE 2016-4-11 18:18 (stable), clicked "Load Firmware (online)," then clicked "Flash Firmware." Got a message "No response from the bootloader, programming failed"
  2. Exited all programs, restarted my computer, updated my Cleanflight configurator to the latest 1.2.2 which then gave me the "Github API Rate limit exceeded" warning. That brought me to this page where I walked through the above laborious steps of creating a API Token just so I could use Cleanflight. Wasn't sure where to enter my API Token, but found an area in the upper right of the screen beside Com port and Baud rate. Entered it there, and it allowed me to use the Cleanflight app again. Still, the same results.
  3. Put a jumper (paper clip) across the "Boot" pins on the board, clicked "No reboot sequence" then plugged in my board via USB. (no flashing light - just a steady blue light comes on) Same message "No response from the bootloader, programming failed"

I'm sure I am doing something wrong that is really basic but this is frustrating... Now, I can't even connect with the Naze using Baseflight. I haven't tried arming the board using the battery and controller, but I doubt that will work because the ESCs are all beeping when I plug in the battery.

Is there a way to erase the board completely and start fresh or...?

                               ***UPDADTE - 30 minutes later***

I went back to Baseflight and was able to reflash Baseflight using "Flash on connect, No reboot sequence, Full Chip Erase" Do I dare try to load cleanflight again or just resign myself to being a 'Baseflight' kind of guy?? :-)

And DARE I did. I went back to Cleanflight and did a "normal" firmware flash (Full chip erase checked, selected the most recent Naze 32 firmware, loaded it from online, and clicked "Flash Firmware") AND IT WORKED!!!

Lesson Learned: If you are having problems going from Baseflight to Cleanflight, reflash baseflight, then try Cleanflight again>?

@michaelchadwick
Copy link

Strangely, I created a personal access token, added it to a non-public, non-repoed dotfile that gets included in .bashrc, and despite re-sourcing it several times (and restarting iTerm), Github still complains. The Homebrew search (the function that keeps asking me to create the token) still fires, regardless, so I'm not sure how necessary the token really is, but I don't want to get blocked by the Github Police, in any case. I've tried the token with and without quotes, and I can echo it on the command line, so I feel like it's accessible.

Any thoughts?

@moooooooo
Copy link

thanks guys n gals. Works well.

@mkravchenko
Copy link

thanks)

@esaruoho
Copy link

Query - how does one dump the API Token via Google Apps Script Editor? I am using the ImportJSON -bit of code I found online and it's telling me that I should send an Authenticated request because API rate limit has been exceeded..

@rjph99
Copy link

rjph99 commented Nov 29, 2018

You can also get to Personal Access Tokens directly by going here: https://github.com/settings/tokens
or the modified instructions from Step 1 if you prefer to click stuff:
In the top menu to the right, click the tools icon and click on(Settings).
Click on “Developer Settings” in the sidebar (to the left).
In the box with the title “Personal Access Tokens”, press the “Create new token” button.

@DivyadbS
Copy link

DivyadbS commented Jan 7, 2019

how can i access github in Rstudio?
I have created token but i stuck to go to Rstudiio

@mattypiper
Copy link

In Mac OS Catalina, the token goes in .zshrc instead of .bash_profile/.bashrc. Might want to update this guide (it's #1 right now on google for "brew github token").

@christopheranderton
Copy link
Author

In Mac OS Catalina, the token goes in .zshrc instead of .bash_profile/.bashrc. Might want to update this guide (it's #1 right now on google for "brew github token").

Logged in (never here anymore) to add that to the guide. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment