从骨干网获取Instagram访问令牌

时间:2014-05-11 21:44:08

标签: javascript backbone.js instagram

我正在通过骨干开发移动应用程序。我需要在Instagram中验证用户身份。 Instagram返回访问令牌,用一个网址重定向我,在这个网址中有我的访问令牌。

例如我去了这个网址:

window.location.replace("https://instagram.com/oauth/authorize/?  client_id=e40f15a****8a66&redirect_uri=http://example.com&response_type=token");

并且Instagram将我重定向到example.com附加我的访问令牌:

www.mysite.com#accesstoken=125424

如何在骨干网中管理和获取访问令牌?

路由器可以拦截此网址吗?

这是我的路由器功能,它调用url来验证用户身份:

var AppRouter = Backbone.Router.extend({
routes: {
        "": "prova",

        "aut":"provaaut",

    },



   provaaut: function(){





  window.location.replace('https://instagram.com/oauth/authorize/?client_id=e40f15a905**66&redirect_uri=http://example.coml&response_type=token');

AFTER WINDOW.LOCATION.REPLACE instagram redirect me to e new url containing token
   HERE I NEED TO GET REDIRECTED URL

   },

有没有办法在javascript中转到网址等待重定向并获取新网址?

1 个答案:

答案 0 :(得分:0)

One Drive auth API遇到了同样的问题。我在路线中使用正则表达式解决了这个问题。

您是否可以将重定向网址设置为此? www.mysite.com/#accesstoken=125424

以下代码应该有效:

       routes : {

            "*default"                  : "index"
        },

       initialize : function() {

            $_ = this;

            $_ .route(/^accesstoken/, "token_redirect");
        },

       token_redirect : function(){
               //do your stuff
        }