如何在隐式 oauth 期间使用 angular 获取 instagram 访问令牌?

How to get instagram access token using angular during implicit oauth?

由于此应用程序旨在 运行 没有服务器支持并且我正在使用 Angular 我无法捕获隐式 oauth 令牌,因为 Angular 不会容忍第二个 hashbang ( #) 在 URL.

Instagram 正在将用户重定向回 http://127.0.0.1:8080/#/oauth/#access_token=TOKEN and Angular automatically redirect's back to http://127.0.0.1:8080/#/

我的路由代码:

app.config(function($routeProvider) {
    $routeProvider
    .when('/', {
        templateUrl: 'templates/index/index.html',
        controller: 'IndexController',
        controllerAs: 'index'
    })
    .when('/oauth/:token', {
        templateUrl: 'templates/oauth/index.html',
        controller: 'OAuthController',
        controllerAs: 'oauth'
    });

    .otherwise({
        redirectTo: '/'
    });
});

有什么方法可以在 Angular 解决之前删除 # 或强制 angular 忽略 #?

目前还不清楚您在这里总共要达到什么目的,但我有一些建议可能会有所帮助。

1) 使用html 5 模式删除散列。 (在你的 app.config 区块中...)

    $locationProvider.hashPrefix('!');
    $locationProvider.html5Mode(true);

并在您的 index.html 中设置适当的基础 href...

<base href="/" target="_blank">

2) 我在这个荒谬的场景中徘徊了很长时间才发现如果你只是想要一个 feed 稍微没有记录,你可以通过调用 http 的服务获取用户最近 20 条帖子...

 $http({
    method: 'GET',
    url: 'http://www.instagram.com/USERNAME/media',
    responseType: 'json'
  })

不需要客户端 ID 或密码。 不需要访问令牌。