我几天都在努力解决这个错误。以下是我获取令牌的步骤。
这是错误
{"error":{"message":"Cannot specify an empty identifier","type":"OAuthException","code":2500,"fbtrace_id":"BIEldWBZras"}}
客户应该直接验证吗?由于错误代码2500,看起来似乎没有建立oauth身份验证。我也不会从错误中理解这句话"无法指定空标识符" 这是目前为止的代码:
func handleExtendFacebookToken(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
shortLivedToken := r.FormValue("token")
tokenExpiration := time.Now().Local()
resp, err := http.Get("https://graph.facebook.com/oauth/access_token?client_id=" + oauthConf.ClientID + "&client_secret=" + oauthConf.ClientSecret + "&grant_type=fb_exchange_token&fb_exchange_token=" +
url.QueryEscape(shortLivedToken))
if err != nil {
fmt.Printf("Get: %s\n", err)
return
}
defer resp.Body.Close()
response, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
var token FacebookToken;
//fmt.Print("response ",string(response))
err = json.Unmarshal(response, &token)
if err != nil {
log.Fatal("error" + err.Error())
return
}
//fmt.Println("duration ", token.AccessToken)
tokenExpiration = tokenExpiration.Add(time.Duration(token.Expiry) * time.Second)
fmt.Println(tokenExpiration)
/*resp, err = http.Get("https://graph.facebook.com/me?id&access_token=" +
url.QueryEscape(token.AccessToken))
if err != nil {
fmt.Printf("Get: %s\n", err)
return
}
defer resp.Body.Close()
response, err = ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf("ReadAll: %s\n", err)
return
}
//fmt.Println(string(response))
token.userId = string(response)*/
token.Expire_Date = tokenExpiration
token.AccessToken = strings.TrimSpace(token.AccessToken)
res, err := oauthConf.Client(oauth2.NoContext, token.convertFacebookToken()).Get("https://graph.facebook.com/me?id")
if err != nil {
fmt.Printf("ReadAll: %s\n", err)
return
}
defer res.Body.Close()
response, err = ioutil.ReadAll(res.Body)
if err != nil {
fmt.Printf("ReadAll: %s\n", err)
return
}
fmt.Println(string (response))
token.saveTokenToDB()
}
答案 0 :(得分:1)
错误发生在?id
res, err := oauthConf.Client(oauth2.NoContext, token.convertFacebookToken()).Get("https://graph.facebook.com/me?id")
我试图像在facebook图中一样使用它(它没有抛出任何错误)。我完全错了。它应该是:
res, err := oauthConf.Client(oauth2.NoContext, token.convertFacebookToken()).Get("https://graph.facebook.com/me?fields=id")