【问题标题】:Get Instagram access token with out reloading page无需重新加载页面即可获取 Instagram 访问令牌
【发布时间】:2014-09-26 07:53:05
【问题描述】:

我的要求如下。

我在页面create.html 我想触发一个弹出窗口说Login with Instagram。当用户单击该弹出窗口时。我想在像 facebook 这样的弹出窗口上对用户进行身份验证,并在不重新加载的情况下在同一页面上获取访问令牌。当我在附加图片时,我将从 instagram 中获取已经包含来自 facebook 的图片的 div,如果我刷新这些图片将会丢失。

我已成功触发请求并获得该访问令牌。但我不确定如何在 ajax 请求中获取类似成功函数的令牌。

要求: https://api.instagram.com/oauth/authorize/?client_id=XXX&redirect_uri=http://localhost:3000/auth/instagram/callback&response_type=code

分辨率: http://localhost:3000/auth/instagram/callback?code=XXXX

如何在我的 create.html 中获取 code=XXXX

我只能使用 javascript 和 jquery。节点?不!

我尝试使用这个库。 https://github.com/Instagram/instagram-javascript-sdk 但它给了我错误。 {"code": 400, "error_type": "OAuthException", "error_message": "JS login temporarily disabled"}.

如果有任何方法可以像 facebook 一样获得这个令牌。(下)

    FB.login(
        function (response) {
            if (response.authResponse) {
            access_token =   FB.getAuthResponse()['accessToken'];
            new facebookLogin(access_token);
            }
        }
    );

或以任何方式获取该 URL code=XXXX。请帮帮我。

谢谢。

【问题讨论】:

    标签: javascript jquery authentication oauth-2.0 instagram


    【解决方案1】:

    只需在回调页面上使用 window.location.search 即可访问查询字符串并解析出代码参数。

    【讨论】:

    • 问题是,我不想要这样的页面。我不想使用其他页面。
    • 在您的创建页面上,启动弹出窗口后,您可以使用 setTimeout 监控弹出窗口中的 url,使用 location.href 来检测您是否导航到回调 url。然后您可以提取代码,关闭窗口并继续。请注意,您在此处使用授权码授予。您需要向 instagram 的令牌端点发送一个帖子,以交换最终访问令牌的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-02
    • 2017-12-06
    • 2014-07-14
    相关资源
    最近更新 更多