Page 1 of 1

Unable to retrieve Access Token from Instagram Plugin

Posted: Wed Aug 06, 2014 1:57 pm
by Bobby Newland

Hi,

I have successfully installed the instagram plug-in. I have my developer account set up with instagram the phone gap oauth plugin installed everything is working. The login directs the user to instagram and then redirects them back to my app with the access token and code in the url but i am unable to retrieve the access token or code from the url. I was looking at the get_Access_token service and ran a test by entering a code in the request parameter and the test is successful and responds with the access token.

So my question is how can i parse the url with javascript and pull out the code and store in in a local storage variable so i can map it to the get_access_token service and and retrieve the access token. here is my url

http://appery.io/app/view/508edc7d-34...

i would like to be able to pull out the code and store it in a variable example

from what i read it is in the search portion of the url but im not sure how to write the code to retrieve it.

http://appery.io/app/view/508edc7d-34...=81a0ae1bf3a44f68ac060718508fbbc9#loggedInProfile

Please help as my app is based on the instagram connectivity

Thanks,

Bobby


Unable to retrieve Access Token from Instagram Plugin

Posted: Wed Aug 06, 2014 3:17 pm
by Evgene Karachevtsev

Hello Bobby,

You can read the parameters from the URL this way: http://stackoverflow.com/questions/90...


Unable to retrieve Access Token from Instagram Plugin

Posted: Wed Aug 06, 2014 6:55 pm
by Bobby Newland

Hi Evgene,

Thanks for the quick reply. I was able to pull the access token out of the url using the following code

var getCode = function(){
x = window.location.href.split("=");
var code = x[1];
localStorage.setItem('token_code', code);
return code;

}
getCode();

Now my problem is that I need to figure out how to get the code to only run if the url is the redirect url because I have tried inserting it everywhere possible in the access token paramter, i tired it as a page load success event and even putting it in a javascript file and none seem to work. I have came to the conclusion that the reason it is not working is because the code is running before the user is redirected back from instagram.

So my question is how can I get the code to run only if the user has been redirected back from instagram so that it actually pulls the access token from the url.

Thanks


Unable to retrieve Access Token from Instagram Plugin

Posted: Thu Aug 07, 2014 11:14 am
by Maryna Brodina

Hello!

Please check how does it work on example with any other service, for instance Facebook http://devcenter.appery.io/tutorials/...


Unable to retrieve Access Token from Instagram Plugin

Posted: Thu Aug 07, 2014 1:33 pm
by Bobby Newland

Hi Maryna,

Thanks for the reply. I am able to retrieve the access token from the url and save it to a local storage variable and get the instagram service to work. But the last piece of the puzzle now is keeping the user connected to instagram. For some reason once you close the app and open it back up the service has to be invoked again and retrieve the access token again. Is it possible to store the access token to the users database for each user so they don't have to manually connect to instagram every time they open the app back up. And if so what would be the best way to do it.

Thanks,
Bobby


Unable to retrieve Access Token from Instagram Plugin

Posted: Thu Aug 07, 2014 11:06 pm
by Yurii Orishchuk

Hi Bobby,

This is not good way to store personal token in DB.

You can store user token in LSV. This type of storage not clears after user close the app. So when app is started you can check LSV that's stores the userToken and if it has value - you don't need to invoke login service. And you need to invoke the login service if this LSV has empty value.

Also you need to delete this LSV token:
1 on logout service.
2 on session expired.

Regards.