duanqiechui2378 2015-08-29 08:17
浏览 49

用于检索google +域配置文件的Golang程序返回403禁止

Can you please help me with the below problem.

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

  1. I have provided all the privileges as listed in https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority

  2. Both Google+ API and Google+ Domain Api are enabled on the account.

This is the function I have written.

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"
 }
}
  • 写回答

1条回答 默认 最新

  • doutui2016 2015-11-18 06:37
    关注

    Forbidden error will occur due to token problem with plus API. After you got token for the person you are authenticating, you can simply write code as below to get people information.

    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))
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端