如果用户已经在一些不同的地方使用 instagram 登录,如何处理 instagram 的身份验证 window

How to handle authentication with instagram, if the user is already logged in with instagram in some different window

我正在 angular 应用程序中集成 Instagram。

为了与 instagram 集成,根据 instagram 开发人员的说法,我遵循以下 3 个步骤 api https://www.instagram.com/developer/authentication/

第一步:引导您的用户获得我们的授权URL

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

第二步:接收来自 Instagram 的重定向

http://your-redirect-uri?code=CODE

第三步:请求 access_token

然后我将在上一步中收到的代码交换为访问令牌。

 curl -F 'client_id=CLIENT_ID' \
-F 'client_secret=CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
-F 'code=CODE' \
https://api.instagram.com/oauth/access_token

如果用户未登录其他window,则上述步骤工作正常。 但是如果用户已经在其他 window,

中使用 instagram 登录

然后 步骤 3 有时会起作用,有时它会给我以下错误

{"error_type"=>"OAuthException", "error_message"=>"Matching code was not found or was already used.", "code"=>400}

我是不是遗漏了什么??

在允许用户登录之前,通过在隐藏的 iframe 中打开 instagram 注销 url 来执行 instagram 注销,如下所示:

$(document).append('<div style="display:none"><iframe src="https://instagram.com/accounts/logout/" width="0" height="0"></iframe></div>');

这将退出 instagram