Golang google extraction + Return 403 domain profile Forbidden

Could you help me with the problem below.

I am just writing simple code to get my google + Domain user profile. 1. I am using a google + Domain account with the domain name spaceandhow.com

  1. I have granted all privileges listed at https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority

  2. The account includes both the Google+ API and the Api Google+ domain.

This is the function I wrote.

func (p *GoogleAUTH) sendGoogleAuthReq(){ fmt.Println("GoogleAUTH package: Enter sendGoogleAuthReq") data, err := ioutil.ReadFile("D:\\Cygwin\\home\\praprasa\\pragna2.json") if err != nil { fmt.Printf("ReadFile error: %s", err) } conf, err := google.JWTConfigFromJSON(data, "https://www.googleapis.com/auth/plus.me") if err != nil { fmt.Println("json error") } client := conf.Client(oauth2.NoContext) resp, err := client.Get("https://www.googleapis.com/plusDomains/v1/people/me") if err != nil { fmt.Printf("GoogleAUTH package: request execution failed: %s", err) return } defer resp.Body.Close() fmt.Println("GoogleAUTH package: response Status:", resp.Status) fmt.Println("GoogleAUTH package: response Headers:", resp.Header) body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("GoogleAUTH package: cannot fetch token: %v", err) return } fmt.Println("GoogleAUTH package: response Body:", string(body)) fmt.Println("GoogleAUTH package: Exit sendGoogleAuthReq") } 

This is the error message I get

 GoogleAUTH package: response Status: 403 Forbidden GoogleAUTH package: response Headers: map[Vary:[Origin X-Origin] X-Frame-Options:[SAMEORIGIN] X-Xss-Protection:[1; mode=block] Cache-Control:[private, max-age=0] Server:[GSE] Date:[Sat, 29 Aug 2015 07:55:47 GMT] Content-Type:[application/json; charset=UTF-8] Expires:[Sat, 29 Aug 2015 07:55:47 GMT] X-Content-Type-Options:[nosniff] Alternate-Protocol:[443:quic,p=1] Alt-Svc:[quic=":443"; p="1"; ma=604800]] GoogleAUTH package: response Body: { "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message": "Forbidden" } ], "code": 403, "message": "Forbidden" } } 
+5
source share
1 answer

A forbidden error will occur due to a token plus API problem. After you receive the token for the person you are checking, you can simply write the code as shown below to get information about people.

 func (p *GoogleAUTH) sendGoogleAuthReq(){ baseUrl := "https://www.googleapis.com/plus/v1/people/me" authbear := "Bearer " authbear += <access_token> cli := &http.Client{} req, _ := http.NewRequest("GET", baseUrl, nil) req.Header.Set("Authorization", authbear) res, _ := cli.Do(req) bo, _ := ioutil.ReadAll(res.Body) fmt.Println(string(bo)) } 
0
source

All Articles