简体   繁体   English

获取Instagram API的访问令牌

[英]Get access token of instagram API

I want to get the access token in order to diaply the images of an account. 我想获取访问令牌以便深入查看一个帐户的图像。 So I display a pop up where the user can connect. 因此,我显示了一个用户可以连接的弹出窗口。 The pop up works but it redirects to instagram site, with the user connected instead of send me the code. 弹出窗口可以工作,但它会重定向到instagram网站,并与用户连接,而不是向我发送代码。 The link to the connection is something like : 连接的链接类似于:

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

I log in and then, it redirects me to : 我登录,然后将其重定向到:

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

I don't understand how I can get the code. 我不明白如何获取代码。 And I also used the exact same code as : https://github.com/radykal/instagram-popup-login 而且我还使用了与以下代码完全相同的代码: https : //github.com/radykal/instagram-popup-login

Can someone help me please ? 有人能帮助我吗 ?

EDIT 编辑

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;
    }

代码正确,我认为您的应用设置存在问题:登录Instagram Developer,转到“管理客户端”,然后在“安全”选项卡上禁用“隐式OAuth”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM