這可能是有點晚,但我沒有找到一個很好的例子來讓人們開始。
開始之前確保你
安裝golang 1.5
安裝谷歌雲SDK(cloud.google.com/sdk - 這將允許本地開發)
創建服務帳戶在您的谷歌appengine /雲端控制檯和下載JSON(API的和身份驗證>證書)
一旦以上是s etup:
設定的路徑爲之前下載的
出口GOOGLE_APPLICATION_CREDENTIALS =〜/目錄中的安全憑證/ CREDENTIALS.json
現在你可以去驗證。
package main
import (
"fmt"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
analytics "google.golang.org/api/analytics/v3"
)
var (
scope = analytics.AnalyticsReadonlyScope
)
func main() {
// Authentication is provided by the gcloud tool when running locally, and
// by the associated service account when running on Compute Engine.
client, err := google.DefaultClient(context.Background(), scope)
if err != nil {
fmt.Printf("Unable to get default client: %v", err)
}
service, err := analytics.New(client)
if err != nil {
fmt.Printf("Unable to create storage service: %v", err)
}
fmt.Println(service)
}
裏面goauth2/oauth/jwt是代碼尋找。謝謝 – Freaktor