package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
)
func main() {
v := url.Values{}
v.Set("grant_type", "client_credentials") //规定,无需修改
v.Add("client_id", "YM1OvG...K") //根据自己申请填写
v.Add("client_secret", "S926...Wq") //根据自己申请填写
res, err := http.PostForm("https://aip.baidubce.com/oauth/2.0/token", v)
robots, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", robots)
}
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
可以了
显示The authorization grant type is not supported是怎么回事??
显示The authorization grant type is not supported是怎么回事??
func auth( apikey, secretkey string ) (string, error) {
client := &http.Client{}
v := url.Values{}
v.Set("grant_type", "client_credentials")
v.Add("client_id", apikey)
v.Add("client_secret", secretkey)
req, err := http.NewRequest("GET", ACCESSTOKE_URL, bytes.NewBufferString(v.Encode()))
if err != nil {
// handle error
return "", err
}
resp, err := client.Do(req)
if err != nil{
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
fmt.Println(string(body))
return string(body), nil
}
请问header里面的authorization是怎么签名?? 有没有代码分享一下????
请问header里面的authorization是怎么签名?? 有没有代码分享一下????
想做个go语言的SDK
做一下记录
分享代码?
获取client_id,client_sectet的方式见
http://ai.baidu.com/docs#/Begin/top
grant_type: 必须参数,固定为client_credentials;
client_id: 必须参数,应用的API Key;
client_secret: 必须参数,应用的Secret Key;