dpr26232 2015-12-26 19:47
浏览 344
已采纳

在golang中打开一个网址,然后阅读重定向的网址

I am writing a command line tool for accessing Medium.com's API using Go. They have released this SDK for golang too.

I have followed the instructions until the point where I can build a url using secret state, redirect url, and scopes.

package main

import (
    "fmt"
    "net/http"

    "github.com/Medium/medium-sdk-go"
)

func check(e error) {
    if e != nil {
        panic(e)
    }
}

func mediumAuth() {
    m := medium.NewClient("clientIDString", "clientSecretString")

    url := m.GetAuthorizationURL("supersecretstring", "http://hasit.me/callback/medium", medium.ScopeBasicProfile, medium.ScopePublishPost)

    //next step
}


func main() {
    mediumAuth()
}

The next step is to open the url to let user give permission for accessing his/her profile. I can successfully open the url.

exec.Command("open", url).Start()

Now, once the user clicks on the url, how can I fetch the redirected url? I even tried using http GET but the response is not the one that I want.

resp, err := http.Get(url)

I am sorry if the answer is obvious but this will be my first program where I use some API in any language. Help will be appreciated.

  • 写回答

1条回答 默认 最新

  • doutinghou6980 2015-12-27 01:08
    关注

    The important shift that needs to happen is around your question how can I fetch the redirected url, because the answer is: You don't. Medium is going to post to this URL. You need to have a webserver somewhere that listens on this URL and parses the response.

    Since you're writing a CLI tool and not a web service, this is probably the inappropriate way to do authentication: Medium provides Self-Issued Access Tokens for use in desktop applications.

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

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘