在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):googleapis/elixir-google-api开源软件地址(OpenSource Url):https://github.com/googleapis/elixir-google-api开源编程语言(OpenSource Language):Elixir 100.0%开源软件介绍(OpenSource Introduction):GoogleApisThis repository contains all the client libraries to interact with Google APIs.
These client libraries are created under The main folder contains the code necessary to generate these client libraries. NOTE: These generated clients are under development and should be considered experimental! UsageInstallationAll available Google API clients can be found on hex.pm. Add a client
to your project's defmodule YourApplication.Mixfile do
use Mix.Project
#...
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:google_api_storage, "~> 0.19.0"},
{:goth, "~> 1.2.0"}
]
end
end
Next, run $ mix deps.get Now you can make an API call by obtaining an access token and using the generated modules. Obtaining an Access TokenService AccountsAuthentication is typically done through Application Default Credentials
which means you do not have to change the code to authenticate as long as
your environment has credentials. Start by creating a
Service Account key file. This file can be used to
authenticate to Google Cloud Platform services from any environment. To use
the file, set the
If you are deploying to App Engine, Compute Engine, or Container Engine, your credentials will be available by default. OAuth 2.0Many APIs (like Drive, Gmail, and YouTube) require you to use OAuth 2.0 to authorize requests on behalf of an authenticated user. For an example using the oauth2-library, see the auth sample. We've also provided a mix task to fetch a token for testing. The following command requests a token for the Drive full access scope: $ export GOOGLE_CLIENT_ID=[YOUR-OAUTH-CLIENT-ID]
$ export GOOGLE_CLIENT_SECRET=[YOUR-OAUTH-CLIENT-SECRET]
$ mix google_apis.auth https://www.googleapis.com/auth/drive
Open the following link in your brower:
https://accounts.google.com/o/oauth2/auth?[some-long-url]
Enter verification code: Once you've logged in and authorized the application, copy the code param from the web browser's url and paste into the console. The script will then fetch your OAuth access token. Token: [your-oauth-token] You can then use this token for your testing: connection = GoogleApi.Drive.V3.Connection.new("your-oauth-token")
{:ok, file_list} = GoogleApi.Drive.V3.Api.Files.drive_files_list(conn) Making a Request# Obtain an access token using goth
{:ok, token} = Goth.Token.for_scope("https://www.googleapis.com/auth/cloud-platform")
conn = GoogleApi.Storage.V1.Connection.new(token.token)
# Call the Storage V1 API (for example) to list buckets
{:ok, response} = GoogleApi.Storage.V1.Api.Buckets.storage_buckets_list(conn, project_id)
# Print the response
Enum.each(response.items, &IO.puts(&1.id)) What's Next?Take a look at our elixir-samples repository repository for examples of calling individual APIs and a getting started tutorial app. Generating ClientsSetup
$> npm install
$> mix deps.get This project provides 4 mix tasks to componentize the build process:
Selecting APIsThe You can change the name of the file by providing a filename argument to the mix task: $> mix google_apis.discover foo.json Note that this task is not one that should be run often, as the
Fetching API SpecificationsThe You can limit which APIs to fetch by providing an API name argument to the mix task: $> mix google_apis.fetch CloudTrace Converting API SpecificationsThe next step is to convert the API specifications from Google's discovery
format to OpenApi format. The You can configure the converter by modifying the config :google_apis, spec_converter: <some converter implementation> The default converter uses the node package api-spec-converter. You can also limit which APIs to convert by providing an API name argument to the mix task: $> mix google_apis.convert CloudTrace Building API ClientsThe You can configure the converter by modifying the config :google_apis, client_generator: GoogleApis.Generator.SwaggerCli The default generator uses Docker and an image based off the swagger-codegen
project. You can further configure this converter by
modifying the config :google_apis, swagger_cli_image: "swagger-cli" You can also limit which APIs to generate by providing an API name argument to the mix task: $> mix google_apis.generate CloudTrace ContributingContributions to this library are always welcome and highly encouraged. See CONTRIBUTING for more information on how to get started. LicenseApache 2.0 - See LICENSE for more information. DisclaimerThis is not an officially supported Google product. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论