dpr26232 2015-12-26 11: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-26 17: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.

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

报告相同问题?

悬赏问题

  • ¥30 怎么把PCK、OKS指标添加到yolov11中
  • ¥15 QT+FFmpeg使用GPU加速解码
  • ¥15 为什么投影机用酷喵播放电影放一段时间就播放不下去了?提示发生未知故障,有什么解决办法吗?
  • ¥15 来个会搭建付费网站的有偿
  • ¥100 有能够实现人机模式的c/c++代码,有图片背景等,能够直接进行游戏
  • ¥20 校园网认证openwrt插件
  • ¥15 以AT89C51单片机芯片为核心来制作一个简易计算器,外部由4*4矩阵键盘和一个LCD1602字符型液晶显示屏构成,内部由一块AT89C51单片机构成,通过软件编程可实现简单加减乘除。
  • ¥15 求GCMS辅导数据分析
  • ¥30 SD中的一段Unet下采样代码其中的resnet是谁跟谁进行残差连接
  • ¥15 Unet采样阶段的res_samples问题
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部