如何使用 REST API 登录 IBM Bluemix?

How to log into IBM Bluemix using REST API?

我正在尝试使用 Cloud Foundry go-cfclient to work with IBM Bluemix and the REST API in Go. I already fail with the login process. I am using the following sample code and invoke the program by passing in the Bluemix endpoint "https://api.ng.bluemix.net”和我的 userid/password 信息。

package main

import (
    "flag"
    "fmt"
    "os"

    cfclient "github.com/cloudfoundry-community/go-cfclient"
)

func main() {
    api := flag.String("api", "", "API endpoint")
    username := flag.String("username", "", "User name")
    password := flag.String("password", "", "password")
    help := flag.Bool("help", false, "help")

    flag.Parse()

    if *help || len(*api) == 0 || len(*username) == 0 || len(*password) == 0 {
        flag.Usage()
        os.Exit(1)
    }

    config := &cfclient.Config{
        ApiAddress: *api,
        Username:   *username,
        Password:   *password}

    fmt.Println("user %v\n",*username)
    var (
        client *cfclient.Client
        err    error
    )

    if client, err = cfclient.NewClient(config); err != nil {
        panic(err)
    }
    fmt.Println(client)

    apps, err := client.ListApps()

    if err != nil {
        panic(err)
    }

    fmt.Println(apps)
}

返回的错误是:

panic: Error getting token: oauth2: cannot fetch token: 401 Unauthorized Response: {"error":"unauthorized","error_description":"Bad credentials"}

需要提供什么信息?如何使用 REST API 登录 Bluemix?

Here is an example 使用 REST API(在 JavaScript 中)登录 Bluemix。

您调用登录端点并从 Bluemix 请求带有您的用户名和密码的令牌。