Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在分析访问令牌的Github响应_Github_Go - Fatal编程技术网

正在分析访问令牌的Github响应

正在分析访问令牌的Github响应,github,go,Github,Go,只是搞乱了GithubAPI和oauth。我已经到了从GH收到access\u令牌的地步 到目前为止,我已经: url := "https://github.com/login/oauth/access_token" params := map[string]string{"client_id": client_id, "client_secret": client_secret, "code": code} data, _ := json.Marshal(params) resp, _ :=

只是搞乱了GithubAPI和oauth。我已经到了从GH收到
access\u令牌的地步

到目前为止,我已经:

url := "https://github.com/login/oauth/access_token"

params := map[string]string{"client_id": client_id, "client_secret": client_secret, "code": code}
data, _ := json.Marshal(params)
resp, _ := http.Post(url, "application/json", bytes.NewBuffer(data))

defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)
但我现在想访问响应部分。根据GH文件,它们是
access\u token=e72e16c7e42f292c6912e7710c8347ae178b4a&scope=user%2Cgist&token\u type=bearer


我需要解析字符串还是有更好的方法?

这是一个URL查询字符串。您可以使用
url
包对其进行解析,并获得
url.Values
(这只是一个映射)


如果您向API发送
Accept
头(也使用
application/json
),您应该会收到一个json响应,该响应可以被取消编组。
resp := "access_token=e72e16c7e42f292c6912e7710c838347ae178b4a&scope=user%2Cgist&token_type=bearer"
values, err := url.ParseQuery(resp)
if err != nil {
    panic(err)
}

fmt.Println("access_token:", values["access_token"])
fmt.Println("token_type:", values["token_type"])