mikefowler / instajam

Instajam is a JavaScript wrapper for the Instagram API. You provide the access token, we provide the jam. Or whatever.
http://mikefowler.github.io/instajam
MIT License
132 stars 33 forks source link

Authenticating with window.open() #4

Closed onyekachiapam closed 10 years ago

onyekachiapam commented 10 years ago

Hi,

Now when I click authenticate button,page goes to instagram then page is postback.I want to authenticate with popup like Facebook Javascript SDK and store localstroage. Is it possible ?

function LoginInstagram() {
            // Get the profile of the authenticated user.
            debugger;
            if (API.authenticated) {
                API.user.self.profile(function (data) {
                    debugger;
                    //showResults(data);
                });
            }
            else {
                window.open(API.authUrl); // Is it require to use callback function or postMessage ???
                if (API.authenticated) { // then code continues this line.
                    API.user.self.profile(function (data) {
                        debugger;
                        //showResults(data);
                    });
                }
                else {
                    alert("Connection Problem...");
                }
            }
        }

Thanks

mikefowler commented 10 years ago

@onyekachiapam, it should be possible with Instajam as it is, but you'll have to write some additional code. Read through this StackOverflow explaining how to do it for Twitter.

Essentially, the popup window will still redirect to your callback page, and the callback page should be responsible for parsing the access token from the URL, and passing it back to the opener:

window.opener.setInstagramToken(myToken);
window.close();

Or something like that. This should point you in the right direction.