D
D
daniyalov2015-02-12 14:43:57
HTML
daniyalov, 2015-02-12 14:43:57

How to insert into HTML the resulting string from the address bar?

I get a token in the address bar after authorizing the application, how can I add the token code to the HTML page with which I made the request? I'm a beginner, and I couldn't deal with the redirect. I get a token only with a non-existent URL (localhost).
request token:

https://instagram.com/oauth/authorize/?client_id=64c696ae6b32405a8efcd83889c571be&redirect_uri=http://localhost&response_type=token

I get the line:
localhost/#access_token=38780608.64c696a.48dffb12745e4103994e71fd895c355e

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2015-02-13
@daniyalov

You can select the desired part of the address after the pound sign (#) like this:

var hash = window.location.hash;

if (hash.length > 1) 
{
    alert('Маркер доступа: ' + hash.substring(hash.indexOf('=') + 1));
}

Example
This code must be on the page specified in the redirect_uri , i.e. in this case, on the page:
As you can see, the access token is stripped from window.location.hash . It can be passed, for example, to a variable:
If you plan to use a different address, then you must specify it in the settings of a specific application .
Unfortunately Instagram only allows one callback address per app at the moment.
The callback address ( redirect_uri ) in the authorization request must exactly match the one specified in the application settings (excluding request parameters).
-------------------------------------------------- -------------
It's better to encode the URL parameters so that there are no problems.
PS: If the access token in the question text is real, then it is not secure. Better to delete and get a new one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question