【问题标题】:Get access token of instagram API获取 Instagram API 的访问令牌
【发布时间】:2017-04-28 07:24:35
【问题描述】:

我想获取访问令牌以显示帐户的图像。所以我显示一个用户可以连接的弹出窗口。弹出窗口有效,但它重定向到 instagram 站点,用户已连接而不是向我发送代码。连接的链接类似于:

https://www.instagram.com/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id=aaaaaaaa&redirect_uri=url&response_type=token

我登录,然后它会将我重定向到:

https://www.instagram.com/oauth/authorize/?client_id=aaaaaaa&redirect_uri=url&response_type=token

我不明白如何获取代码。而且我还使用了完全相同的代码:https://github.com/radykal/instagram-popup-login

有人可以帮帮我吗?

编辑

var loc = window.location.host+window.location.pathname;

var accessToken = null; //the access token is required to make any endpoint calls, http://instagram.com/developer/endpoints/
    var authenticateInstagram = function(instagramClientId, instagramRedirectUri, callback) {
        //the pop-up window size, change if you want
        var popupWidth = 700,
            popupHeight = 500,
            popupLeft = (window.screen.width - popupWidth) / 2,
            popupTop = (window.screen.height - popupHeight) / 2;
        //the url needs to point to instagram_auth.php
        var popup = window.open('instagram_auth.php', '', 'width='+popupWidth+',height='+popupHeight+',left='+popupLeft+',top='+popupTop+'');
        popup.onload = function() {
            //open authorize url in pop-up
            if(window.location.hash.length == 0) {
                popup.open('https://instagram.com/oauth/authorize/?client_id='+instagramClientId+'&redirect_uri='+instagramRedirectUri+'&response_type=token', '_self');
            }

            //an interval runs to get the access token from the pop-up
            var interval = setInterval(function() {
                try {
                    console.log(window.location);
                    //check if hash exists
                    if(popup.location.hash.length) {
                        //hash found, that includes the access token
                        clearInterval(interval);
                        accessToken = popup.location.hash.slice(14); //slice #access_token= from string
                        popup.close();
                        if(callback != undefined && typeof callback == 'function') callback();
                    }
                }
                catch(evt) {
                    //permission denied
                    console.log("error");
                }
            }, 100);
        }
    };
    function login_callback() {
        alert("You are successfully logged in! Access Token: "+accessToken);
    }
    function login() {
        authenticateInstagram(
            '16edb5c3bc05437594d69178f2aa646a', //instagram client ID
            'localhost/facebook', //instagram redirect URI
            login_callback //optional - a callback function
        );
        return false;
    }

【问题讨论】:

    标签: javascript instagram access-token instagram-api


    【解决方案1】:

    代码没问题,我认为是您的应用设置有问题:登录 Instagram 开发人员,转到“管理客户端”,然后在“安全”选项卡中禁用“隐式 OAuth”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2016-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      相关资源
      最近更新 更多