【问题标题】:problem with python request.get when trying to get instagramm access code尝试获取instagram访问代码时python request.get的问题
【发布时间】:2022-01-23 00:33:37
【问题描述】:

我在尝试使用 request.get() 方法构造 url 来处理 instagramm oauth 时遇到问题

这就是我正在做的:

def get_code(uri, id):
    params = {
    'client_id': id
    ,'redirect_uri': uri
    ,'scope': 'user_profile,user_media'
    ,'response_type': 'code'
    }
    r = requests.get('https://www.instagram.com/oauth/authorize/'
    ,params = params)
    input(r.url)

以及使用此类参数调用函数时

get_code('https://6b4c-46-39-51-57.ngrok.io/autos/', 96597520768760)

打印 r.url 时我期待这样的 url:

https://www.instagram.com/oauth/authorize?client_id=965975207687609&redirect_uri=https://6b4c-46-39-51-57.ngrok.io/autos/&scope=user_profile,user_media&response_type=code

但是看看我得到了什么:

https://www.instagram.com/accounts/login/?force_authentication=1&enable_fb_login=1&next=/oauth/authorize/%3Fclient_id%3D96597520768760%26redirect_uri%3Dhttps%3A//6b4c-46-39-51-57.ngrok.io/autos/%26scope%3Duser_profile%2Cuser_media%26response_type%3Dcode

有人知道为什么 request.get().ull 返回给我的不是我试图构建的 url 吗?

【问题讨论】:

    标签: python python-requests instagram-api


    【解决方案1】:

    尝试在浏览器的私有模式下访问第一个链接,您会注意到您将被重定向到第二个链接,因为您尚未登录,并且无权访问所询问的资源。

    so requests,实际上是向第一个链接发送 get 请求,但请求被重定向到第二个链接。

    【讨论】:

    • 似乎我对 .url 属性的含义不太了解。我认为它存储了为初始请求构建的 url。不是我们被重定向到或以某种方式得到响应的东西
    • @Ignat 如果我的回答有帮助,请接受。
    猜你喜欢
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多