使用 Go SDK
中的示例,返回用户名和 apikey
{"error":"Access Denied. ","code":"SoftLayer_Exception_Public"}
package main
import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/sl"
)
func main() {
userName := "xxxx"
apikey := "xxxx"
sess := session.New(userName, apikey)
sess.Debug = true
doListAccountVMsTest(sess)
}
func doListAccountVMsTest(sess *session.Session) {
service := services.GetAccountService(sess)
vms, err := service.Mask("id;hostname;domain").Limit(10).GetVirtualGuests()
if err != nil {
fmt.Printf("Error retrieving Virtual Guests from Account: %s\n", err)
return
} else {
fmt.Println("VMs under Account:")
}
for _, vm := range vms {
fmt.Printf("\t[%d]%s.%s\n", *vm.Id, *vm.Hostname, *vm.Domain)
}
}
func handleError(err error) {
apiErr := err.(sl.Error)
fmt.Printf(
"Exception: %s\nMessage: %s\nHTTP Status Code: %d\n",
apiErr.Exception,
apiErr.Message,
apiErr.StatusCode)
}
最佳答案
我在运行您的代码时没有遇到任何问题,我建议您检查您发送的用户名和 apikey。查看您个人资料中的API 访问信息部分https://control.softlayer.com/account/user/profile
关于go - 软层 SDK SoftLayer_Exception_Public : Access Denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47922453/