As you know, a gallery ID is no longer isolated to the web app. It is not even tied to a single page or instance of the Gallery control on the page. For instance, one can dynamically assign a gallery ID early in the page life cycle so that the page is capable of showing different galleries to different users.
So, to answer your question, we need to know what gallery you *want* to get, and then we can figure out how to get the gallery ID. Your question implies you will always have an album ID in the query string. Is that true? If so, then loading the album and grabbing the gallery ID from it is the best way. That's how GSP does it when the 'aid' query string is present.
Roger Martin
Creator and Lead Developer of Gallery Server Pro