@@ -48,6 +48,34 @@ func Example_webServer() {
48
48
client .Get ("..." )
49
49
}
50
50
51
+ func Example_serviceAccountsJSON () {
52
+ // Your credentials should be obtained from the Google
53
+ // Developer Console (https://console.developers.google.com).
54
+ // Navigate to your project, then see the "Credentials" page
55
+ // under "APIs & Auth".
56
+ // To create a service account client, click "Create new Client ID",
57
+ // select "Service Account", and click "Create Client ID". A JSON
58
+ // key file will then be downloaded to your computer.
59
+ config , err := google .NewServiceAccountJSONConfig (
60
+ "/path/to/your-project-key.json" ,
61
+ "https://www.googleapis.com/auth/bigquery" ,
62
+ )
63
+ if err != nil {
64
+ log .Fatal (err )
65
+ }
66
+ // Initiate an http.Client. The following GET request will be
67
+ // authorized and authenticated on the behalf of
68
+ // your service account.
69
+ client := http.Client {Transport : config .NewTransport ()}
70
+ client .Get ("..." )
71
+
72
+ // If you would like to impersonate a user, you can
73
+ // create a transport with a subject. The following GET
74
+ // request will be made on the behalf of user@example.com.
75
+ client = http.Client {Transport : config .NewTransportWithUser ("user@example.com" )}
76
+ client .Get ("..." )
77
+ }
78
+
51
79
func Example_serviceAccounts () {
52
80
// Your credentials should be obtained from the Google
53
81
// Developer Console (https://console.developers.google.com).
0 commit comments