5

你能帮我解决以下问题吗?

我只是在编写一个简单的代码来检索我的 google+ 域用户个人资料。1. 我正在使用域名为 spaceandhow.com 的 google+ 域帐户

  1. 我已提供https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority中列出的所有权限

  2. 帐户上同时启用了 Google+ API 和 Google+ Domain Api。

这是我写的函数。

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")   
}

这是我收到的错误消息

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"
 }
}
4

1 回答 1

0

由于 plus API 的令牌问题,将发生禁止错误。在您获得要验证的人的令牌后,您可以简单地编写如下代码来获取人员信息。

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))
}
于 2015-11-18T06:37:04.617 回答