Instagram API: force prompt during authentication

浪尽此生 提交于 2019-12-22 03:48:18

问题


Is there a way for the instagram auth(login) to always ask for authentication? This is skipped when the user is logged in and has already authorized the app.

It would be something like twitter's use_authorize=true or google's approval_prompt=force.


回答1:


I believe that the most simple way is to use next url:

https://instagram.com/accounts/logoutin/?force_classic_login=&next=URLENCODED_INSTAGRAM_OAUTH_URI_PATH_WITH_YOUR_DATA

For example:

window.location.assign('https://instagram.com/accounts/logoutin/?force_classic_login=&next=' + encodeURIComponent('/oauth/authorize/?response_type=code&scope=public_content+follower_list+comments&client_id='+ YOUR_IG_CLIENT_ID + '&redirect_uri='+encodeURIComponent(YOUR_REDIRECT_URI)));

Please take a note that your redirect uri should be encoded twice




回答2:


I managed to get it working:

I try loading an image with the url of the instagram logout page before opening the authorize popup.
Something like this (coffeescript):

windowOpen = ->
    window.open("/instagram/authorize?...")

if forceLogin
    tryLogout().always ->
        windowOpen()

And the tryLogout function (setTimeout 10seconds as a fallback)

tryLogout: ->
    deferred = $.Deferred()
    logOutImg = new Image()

    logOutImg.onerror = ->
        deferred.resolve()
    logOutImg.onload = ->
        deferred.resolve()

    logOutImg.src = 'https://instagram.com/accounts/logout/'

    setTimeout(->
        deferred.reject()
    , 10000)

    return deferred.promise()



回答3:


Here is the solution : you have to delete the Instagram cookie named sessionid from your browser so Instagram doesn't recognize you anymore

Solution for Android is here : https://stackoverflow.com/a/26847187/328845



来源:https://stackoverflow.com/questions/24550048/instagram-api-force-prompt-during-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!