Generate Google Drive Api Keys

18.04.2020by
Generate Google Drive Api Keys 8,8/10 4098 reviews

These instructions apply for non Google Cloud Platform (GCP) APIs. If you're building a GCP application, see using API keys for GCP. If your client application does not use OAuth 2.0, then it must include an API key when it calls an API that's enabled within a Google Cloud Platform project. Apr 13, 2020  Click Select a project, choose a project, and click Open. In the left nav, click Service accounts. Find the row of the service account that you want to create a.

To display your app in Google Drive when a user creates or opens a file,you must first configure a Drive UI integration. Configuration is alsorequired to list your app in the G Suite Marketplace.

  1. Sign in to the Google API Console.
  2. At the top of the page, next to the Google APIs logo, select your app’sproject. The APIs and Services dashboard appears.
  3. At the bottom of the APIs & Services dashboard, click Google Drive API.If you don’t see this option, you must enable the Google Drive API.
  4. In the left-hand nav, click Drive UI Integration. The Configuration pageappears.
  5. Enter an application name in the Application Name field. The applicationname is displayed to users in the Manage apps dialog in the Google Drive UI(gear icon > settings > Manage Apps).
  6. Enter a short description in the Short Description field. The shortdescription is displayed to users in the Manage apps dialog in the Google DriveUI (gear icon > settings > Manage Apps).
  7. (optional) Enter a long description in the Long Description field.
  8. Upload one or more icons to display in a user's list of connected Drive appsand in the 'Open with' context menu item. Icons should be in PNG format with atransparent background. Icons can ake up to 24 hours to appear in Drive.

    Note: Document icons are deprecated. Your application icon appears next toshortcut and third-party shortcut files. A set of standard icons is used forother file types.
  9. If you want to allow users to use the Drive UI's 'Open with' context menuitem, enter a url to your app in the Open URL field. This URL is used by the'Open With' context menu item.

    • This URL must contain a fully-qualified domainname; localhost doesn't work.
    • You mustverify ownership of this URLbefore you can list your app in the G Suite Marketplace.
    • By default, a state query parameter is appended to this URL to pass datafrom the Drive UI to your app. For information on the contents of thestate parameter, refer toThe state parameter.
    Warning: Automatically showing OAuth 2.0 consent screen is deprecated. Don'tselect this option. All authorization requests must be initiated by theapplication.
  10. Enter default mime types and file extensions in theDefault Mime Types and Default File Extensions fields. Defaultmime types and file extensions represent files that your app is uniquely builtto open. For example, your app might open a native format for layering andediting images. Only include standardmedia typesor G Suite and Drive MIME typesand make sure they’re free of typos and misspellings. If your app only opensshortcut or third-party shortcut files, you can leave MIME type blank.

  11. Enter secondary mime types and file extensions in the Secondary MimeTypes and Secondary File Extensions fields. Secondary mime types andfile extensions represent files that your app can open, but aren’t specific toyour app. For example, your app might be an image editing app that opens png andjpg images. Only include standardmedia typesor G Suite and Drive MIME typesand make sure they’re free of typos and misspellings. If your app only opensshortcut or third-party shortcut files, you can leave MIME type blank.

    Note: If a user installs multiple Drive apps that can open a file, themost-recently installed app is used until the user chooses another app.
  12. If you want users to click on the Drive UI's New button and create a new filewith your app, check Allow users to create new documents using thisapplication. The New URL and Document Name fields appear.

    • This URL must contain a fully-qualified domainname; localhost doesn't work.
    • You mustverify ownership of this URLbefore you can list your app in the G Suite Marketplace.
    • By default, a state query parameter is appended to this URL to pass datafrom the Drive UI to your app. For information on the contents of thestate parameter, refer toThe state parameter.
  13. Enter a url in the New URL field. This URL is used by the'New' button to redirect the user to your application.

    Note: Leave the Document Name field blank. This field is no longer used.
  14. (Optional) If you want your app to be able to open G Suite-supportedfiles, check Importing.

  15. (Optional) If your app needs to manipulate files on shared drives, checkShared drive support. For further information on how to support shareddrives in your app, refer to Implement shared drive support

  16. Click Save Changes.

Request the drive.install scope

You must request thehttps://www.googleapis.com/auth/drive.install scope to integrate withthe Drive UI. When requesting this scope, users see a dialog similar to this:

For more information about scopes you can request for Drive apps, and how torequest them, see What scope or scopes does my app need?

Note: If your app ispublished to the G Suite Marketplace, users anddomain administrators can search for and install the app directly from theG Suite Marketplace.

The state parameter

By default, a state parameter is appended to the Open and New URL to pass datafrom the Drive UI to your app. This parameter contains a JSON-encoded stringcontaining template variables with data about the request to your app. Thevariables included depend on the type of URL used (Open URL or New URL):

Template variableDescriptionApplicable to which URL type?
{ids}A comma-separated list of file IDs that are being opened.Open URL
{exportIds}A comma-separated list of file IDs that are being exported (used only when opening native Google documents).Open URL
{folderId}The id of the parent folder.New URL
{userId}The profile ID that uniquely identifies the user.Open URL and New URL
{action}The action being performed. This value is open when using an Open URL or create when using a New URL. Open URL and New URL

The state parameter is URL-encoded, so your app must handle the escapecharacters and parse it as JSON. Apps can detect the create value in thestate parameter to verify that this is a request to create a new file.

Example state information for a New URL (in JSON notation)

The state information for a New URL is:

Example state information for an Open URL (in JSON notation)

The state information for an Open URL is:

The ids are used to fetch file metadata and download file content. Once it hasthe file ID and an access token, your app can check permissions,fetch the file metadata, and download the file content as described in thereference documentation for files.get.

Note: All apps, including apps opening files from shortcuts and third-partyshortcuts, should callfiles.get to check the user's permissions fora document. Apps should warn read-only users when they are opening a file theycannot edit or save (instead of letting them spend time editing, and thengiving an error on save).

Next steps

An installed app needs to be able to handle create and open actionslaunched from the Drive UI. SeeHandle a New URLorHandle a Open URLto learn more.

When your application requests private data, the request must be authorized by an authenticated user who has access to that data.

When your application requests public data, the request doesn't need to be authorized, but does need to be accompanied by an identifier, such as an API key.

Every request your application sends to the Google Sheets API needs to identify your application to Google. There are two ways to identify your application: using an OAuth 2.0 token (which also authorizes the request) and/or using the application's API key. Here's how to determine which of those options to use:

  • If the request requires authorization (such as a request for an individual's private data), then the application must provide an OAuth 2.0 token with the request. The application may also provide the API key, but it doesn't have to.
  • If the request doesn't require authorization (such as a request for public data), then the application must provide either the API key or an OAuth 2.0 token, or both—whatever option is most convenient for you.

About authorization protocols

Google Drive Api V3

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.

Key generator in java example excel But let say you wish to have have just one new unique value, you have 948576 of not yet taken options out of all 1048576.

Authorizing requests with OAuth 2.0

Generate facebook access token key. Requests to the Google Sheets API for non-public user data must be authorized by an authenticated user.

The details of the authorization process, or 'flow,' for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

  1. When you create your application, you register it using the Google API Console. Google then provides information you'll need later, such as a client ID and a client secret.
  2. Activate the Google Sheets API in the Google API Console. (If the API isn't listed in the API Console, then skip this step.)
  3. When your application needs access to user data, it asks Google for a particular scope of access.
  4. Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
  5. If the user approves, then Google gives your application a short-lived access token.
  6. Your application requests user data, attaching the access token to the request.
  7. If Google determines that your request and the token are valid, it returns the requested data.

Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.

Here's the OAuth 2.0 scope information for the Google Sheets API:

ScopeMeaning
https://www.googleapis.com/auth/spreadsheets.readonlyAllows read-only access to the user's sheets and their properties.
https://www.googleapis.com/auth/spreadsheetsAllows read/write access to the user's sheets and their properties.
https://www.googleapis.com/auth/drive.readonlyAllows read-only access to the user's file metadata and file content.
https://www.googleapis.com/auth/drive.filePer-file access to files created or opened by the app.
https://www.googleapis.com/auth/drive Full, permissive scope to access all of a user's files. Request this scope only when it is strictly necessary.

To request access using OAuth 2.0, your application needs the scope information, as well asinformation that Google supplies when you register your application (such as the client ID and theclient secret).

Acquiring and using an API key

Requests to the Google Sheets API for public data must be accompanied by an identifier, which can be an API key or an access token.

To acquire an API key:

  1. Open the Credentials page in the API Console.
  2. This API supports two types of credentials. Create whichever credentials are appropriate for your project:
    • OAuth 2.0: Whenever your application requests private user data, it must send an OAuth 2.0 token along with the request. Your application first sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.

      For more information, see the OAuth 2.0 documentation.

    • API keys: A request that does not provide an OAuth 2.0 token must send an API key. The key identifies your project and provides API access, quota, and reports.

      The API supports several types of restrictions on API keys. If the API key that you need doesn't already exist, then create an API key in the Console by clicking Create credentials > API key. You can restrict the key before using it in production by clicking Restrict key and selecting one of the Restrictions.

Generate Google Drive Api Keys Download

To keep your API keys secure, follow the best practices forsecurely using API keys.

After you have an API key, your application can append the query parameterkey=yourAPIKey to all request URLs.

Generate Google Drive Api Keys Windows 10

The API key is safe for embedding in URLs; it doesn't need any encoding.

Comments are closed.