简体   繁体   中英

Instagram API: how to automatically receive access token in Java application?

Hello everyone!

I am writing an application in Java which retrieves information from Instagram server by their API, accumulates it and builds a visualization map. The problem is that I cannot automate the authentication process. The official Instagram API documentation states that: In order to receive an access_token, you must do the following:

Direct the user to our authorization url. If the user is not logged in, they will be asked to log in. The user will be asked if they would like to grant your application access to her Instagram data. The server will redirect the user in one of two ways that you choose:"

So it is a compulsory step for a user to login manually into his/her account. I believe that this is done in order to grant permissions to an app that uses Instagram API on behave of a user, for example, if it makes some posts in his/her account. However, I am not going to use any user's personal account. In fact I set up a seperate account for my application and registered the app (I got client_id, client_secret and set the redirect_uri). So I want only to use those credentials in order to get updated access token and make some REST API posts to Instagram.

What I do now, I make a GET request, receive back a login html page, parse it, insert my account credentials and after I make a POST request I receive the 400 code:

Sending 'GET' request to URL : instagram.com/oauth/authorize/?client_id=CLIENT_ID&redirect_uri=localhost&response_type=code

Response Code : 200 Extracting form data...

Sending 'POST' request to URL : instagram.com/oauth/authorize/?client_id=CLIET_ID&redirect_uri=localhost&response_type=code Request content:CONTENT&username=LOGIN&password=PASSWORD&=Log+in

Response Code : 302

Sending 'POST' request to URL : www.instagram.com/oauth/authorize/?client_id=CLIENT_ID&redirect_uri=localhost&response_type=code Request content:CLIENT_ID&username=LOGIN&password=PASSWORD&=Log+in

Response Code : 400

I don't understand why am I redirrected one more time. I am assuming that is because some security issues, maybe some hidden fields... do you have any ideas? I appriciate any ideas and possible solutions to the problem. Thanks!

As i can understand from the requests it uses oath protocol which is common for google , twitter and more popular site authentication protocol.

Why not trying an oath library such as

https://github.com/google/google-oauth-java-client

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM