doujiao1180 2017-02-07 17:46
浏览 146
已采纳

如何使用REST API登录到IBM Bluemix?

I am trying to use the 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" and my userid/password info.

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
",*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)
}

The error returned is:

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

What information needs to be provided? How can I log into Bluemix using the REST API?

  • 写回答

1条回答 默认 最新

  • dtry54612 2017-02-08 04:45
    关注

    Here is an example of logging into Bluemix using the REST API (in JavaScript).

    You make a call to the login endpoint and request a token with your username and password from Bluemix.

    body of request

    headers of request

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记