title: Use Google Cloud Storage API with Go AppEngine
body: <p>I've written a test code to list buckets from <a href="https://cloud.google.com/storage/docs/" rel="nofollow">Google Cloud Storage</a> through the Cloud Storage API, however I'm getting the error below when I run the code:</p>
  
  <pre><code>googleapi: Error 403: Forbidden, forbiddenFinished
  </code></pre>
  
  <p>I've checked the permissions and the appengine service account has access to the buckets and both the appengine app and cloud storage bucket are on the same project.</p>
  
  <p>This is my sample code:</p>
  
  <pre><code>package src
  
  import (
      "fmt"
      "net/http"
      "golang.org/x/oauth2/google"
      storage "google.golang.org/api/storage/v1"
      appengine "google.golang.org/appengine"
  )
  
  func init() {
      http.HandleFunc("/", index)
  }
  
  func ListBuckets(r *http.Request, projectID string) ([]*storage.Bucket, error) {
  
      ctx := appengine.NewContext(r)
  
      client, err := google.DefaultClient(ctx, storage.DevstorageReadOnlyScope)
      if err != nil {
          return nil, err
      }
  
      service, err := storage.New(client)
      if err != nil {
          return nil, err
      }
  
      buckets, err := service.Buckets.List(projectID).Do()
      if err != nil {
          return nil, err
      }
  
      return buckets.Items, nil
  }
  
  func index(w http.ResponseWriter, r *http.Request) {
      r.Header.Set("x-goog-project-id", "theIdProvidedByTheAPI")
      bucket, err := ListBuckets(r,"myProject")
      if err != nil {
          fmt.Fprint(w,err.Error())
      }
      for i:=range bucket {
      fmt.Fprint(w,bucket[i].Name)
      }
      fmt.Fprint(w,"\n","Finished.")
  
  }
  </code></pre>
  
  <p>And this is the yaml file:</p>
  
  <pre><code>application: myProject
  version: alpha-001
  runtime: go
  api_version: go1
  
  handlers:
  
  - url: /
    script: _go_app
  </code></pre>
  
  <p>The error message is nor helpful as it does not provide much useful information. I just can't figure out what I'm missing.</p>