How to Use Google API Keys

298 篇文章 2 订阅

API Keys

Some features of Chromium use Google APIs, and to access those APIs, either an API Key or a set of OAuth 2.0 tokens is required. These instructions apply to Chromium version 23 and higher.

You can specify the API keys to use either when you build Chromium, or at runtime using environment variables. First, you need to acquire keys for yourself.

The keys you acquire are not for distribution purposes and must not be shared with other users.

Acquiring Keys

  1. Make sure you are a member of chromium-dev@chromium.org (you can just subscribe to chromium-dev and choose not to receive mail).For convenience, the APIs below are only visible to people subscribed to that group.
  2. Make sure you are logged in with the Google account associated with the email address that you used to subscribe to chromium-dev.
  3. Go to https://cloud.google.com/console
  4. Click the red Create project... button.
  5. (Optional) You may add other members of your organization or team on the Team tab.
  6. In the 'APIs & auth' > APIs tab, click the On/Off button to turn each of the following APIs to the On position, and read and agree to the Terms of Service that is shown: (This list might be out of date; try searching for APIs starting with "Chrome" or having "for Chrome" in the name.)
    • Chrome Remote Desktop API
    • Chrome Spelling API
    • Chrome Suggest API
    • Chrome Sync API
    • Chrome Translate Element
    • Google Maps Geolocation API (requires enabling billing but is free to use; you can skip this one, in which case geolocation features of Chrome will not work)
    • Safe Browsing API
    • Speech API
    • Time Zone API
    • Google Cloud Messaging for Chrome
    • Google Now For Chrome API (Optional, enabled to show Google Now cards)
    • Google+ API
    (Optional) If you are doing Chrome OS work you may also want:
    Chrome OS Hardware ID API
    Chrome OS Registration API
    If any of these APIs are not shown, recheck step 1.
  7. Go to the Credentials tab under the APIs & auth tab.
  8. Click the red Create New Client ID button in the OAuth section to create an OAuth 2.0 client ID.
    1. You want "Installed Application" for the Application type section
    2. You want "Other" for the Installed application type section
  9. A new box should now appear titled “Client ID for installed applications”. In the next sections, we will refer to the values of the “Client ID” and “Client secret” fields in this box later (below).
  10. Click the red Create New Key button in the Public API Access section and create a new Browser key.
    1. You want to leave the box on the "Create a browser key and configure allowed referers" empty.
  11. A new box should appear titled "Key for browser applications". The next sections will refer to the value of the “API key” field too.
  1. Note that the keys you have now acquired are not for distribution purposes and must not be shared with other users. 

Providing Keys at Build Time

If you are building Chromium yourself, you can provide keys as part of your build configuration, that way they are always baked into your binary. To do this, specify a few variables to gyp (there are three ways to do this; see the Setup section on this page ). One easy way is to create, or edit, the file ~/.gyp/include.gypi (or C:\Users\yourusername\.gyp\include.gypi if you’re on Windows), with contents like the following:

{
 'variables': {
   'google_api_key':               'your_api_key
',
   'google_default_client_id':     'your_client_id',
   'google_default_client_secret': 'your_client_secret
',

   # … other variables you may have ...
 },
}


where the text “(your API_KEY)” is replaced with your API_KEY value, and so forth.

Once you’ve done this, run gclient sync or gclient runhooks, and your builds after that will use your keys.

Note that the above is equivalent to providing more flags gyp, i.e. build/gyp_chromium -Dgoogle_api_key='...' -Dgoogle_default_client_id='...' -Dgoogle_default_client_secret='...'

Depe nding on the way you build Chromium, the latter may be more practical for you.

Providing Keys at Runtime

If you prefer, you can build a Chromium binary (or use a pre-built Chromium binary) without API keys baked in, and instead provide them at runtime. To do so, set the environment variables GOOGLE_API_KEY, GOOGLE_DEFAULT_CLIENT_ID and GOOGLE_DEFAULT_CLIENT_SECRET to your " API key", "Client ID" and "C lient secr et" values respectively.

Getting Keys for Your Chromium Derivative

Many of the Google APIs used by Chromium code are specific to Google Chrome and not intended for use in derived products.  In the API Console (http://developers.google.com/console) you may be able to purchase additional quota for some of the APIs listed above.  For APIs that do not have a "Pricing" link, additional quota is not available for purchase.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值