Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Go Example

This page discusses how you can use the Google APIs Client Library for Go to send requests to the Google Cloud Storage JSON API. Specifically, the GitHub sample storage-getting-started-go is discussed.

This document assumes that you have Go installed, and you are familiar with Java and the Google Cloud Storage concepts and operations presented in the Getting Started: Using the Developers Console guide.

1. Set up your environment

To run this example, you need to have Go and Mercurial installed. Mercurial is used to pull in the repositories you need to run this sample:

$ go get code.google.com/p/goauth2/oauth
$ go get code.google.com/p/google-api-go-client/storage/v1

2. Create a client ID and secret

In the example code, you need to provide a client ID and secret to authenticate with the Google Cloud Storage JSON API. You can get these from the Google Developers Console.

To generate a Client ID and secret:

  1. Go to the Google Developers Console .
  2. Select a project to which the client ID will be associated.
  3. In the left sidebar, under APIs & AUTH , select Credentials .
  4. Click Create new Client ID .
  5. In the Create Client ID window, choose Installed application .
  6. Click Create Client ID .

    The resulting client ID will look like the following example:

    Public/Private Key Pair
  7. Click Download JSON .

3. Create your code file

In this step, you will create the Go code file, storage-sample.go . Copy the code from below and make the following changes:

  • Set bucketName to the name of a bucket in the project where you created the client ID.
  • Set projectID to the project name or ID.
  • Set clientId to the client ID you created.
  • Set clientSecret to the client secret associated with the client ID.

storage-sample.go

4. Run the sample

When you run the sample for the first time, you will be asked to grant access to your application by visiting a URL and getting a code (OAuth token), which you then pass as an argument when running the program.

To run the sample for the first time:

  1. Generate an authentication URL.

    $ go run storage-sample.go
    
  2. Open the authentication URL and click Accept .

  3. Copy the code and use it in a new run command:

    $ go run storage-sample.go -code=YOUR_CODE
    

For subsequent runs, you do not need to provide the code.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.