Go 无法获取令牌错误使用oauth2获取amazondrive的身份验证代码
我试图通过命令行应用程序访问amazon drive。 我还在amazon上创建了一个安全配置文件,并启用了amazon登录。 main函数调用Go 无法获取令牌错误使用oauth2获取amazondrive的身份验证代码,go,oauth-2.0,Go,Oauth 2.0,我试图通过命令行应用程序访问amazon drive。 我还在amazon上创建了一个安全配置文件,并启用了amazon登录。 main函数调用Setup()函数 package main import ( "fmt" "github.com/fatih/color" "github.com/toqueteos/webbrowser" "golang.org/x/oauth2" ) type ACDriveStore struct { Config
Setup()
函数
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/toqueteos/webbrowser"
"golang.org/x/oauth2"
)
type ACDriveStore struct {
Config oauth2.Config `json:"oauth_config"`
OAuthToken oauth2.Token `json:"oauth_token"`
}
func (acd *ACDriveStore) Setup() bool {
config := receiveConfig()
token, err := getACDriveTokenFromWeb(config)
if err != nil {
color.Red("Unable to get client token: %v", err)
return false
}
acd.OAuthToken = *token
return false
}
func getACDriveTokenFromWeb(config *oauth2.Config) (*oauth2.Token, error) {
authURL := config.AuthCodeURL("go-acd", oauth2.AccessTypeOffline)
webbrowser.Open(authURL)
color.Yellow("Enter Auth Code: ")
var authCode string
if _, err := fmt.Scan(&authCode); err != nil {
color.Red("Unable to read authentication code %v", err)
return nil, err
}
tok, err := config.Exchange(oauth2.NoContext, authCode)
if err != nil {
color.Red("Unable to retrieve token from web %v", err)
return tok, err
}
return tok, nil
}
func receiveConfig() *oauth2.Config {
var appKey, appSecret string
appKey, appSecret = AmazonDriveClientKey, AmazonDriveClientSecret
return &oauth2.Config{
ClientID: appKey,
ClientSecret: appSecret,
Endpoint: oauth2.Endpoint{
AuthURL: "https://www.amazon.com/ap/oa",
TokenURL: "https://api.amazon.com/auth/o2/token",
},
RedirectURL: "https://go-acd.appspot.com/oauth",
Scopes: []string{"clouddrive:read", "clouddrive:write"},
}
}
但我得到了这个错误
oauth2:无法获取令牌:400错误请求
响应:{“error”:“invalid_request”,“error_description”:“请求缺少必需的参数:code”}
空的
扫描后是否检查了
authCode
的值?试着这样做,那不行。。。我应该在网站显示身份验证码后在终端上粘贴身份验证码…这就是错误出现的地方。。