获取Instagram API的访问令牌 [英] Get access token of instagram API

查看:162
本文介绍了获取Instagram API的访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取访问令牌以便深入查看帐户的图像.因此,我显示了一个用户可以连接的弹出窗口.弹出窗口可以工作,但是它会重定向到instagram网站,并与用户连接,而不是向我发送代码.连接的链接类似于:

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. 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

我不明白如何获取代码.而且我还使用了与以下代码完全相同的代码: https://github.com/radykal/instagram-弹出式登录

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

有人可以帮我吗?

编辑

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".

The code is ok, I think it is a problem with your app settings: Login to Instagram Developer, go to "Manage Client" and the "security" tab an disable "Implicit OAuth".

这篇关于获取Instagram API的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆