Tuesday, 3 December 2019

OAuthAccessTokenException-The access_token provided is invalid Instagram new api

I am integrating Instagram login into my application. As per the provided documentation in bellow link: https://www.instagram.com/developer/authentication/

For getting CODE I hit follow API:

https://api.instagram.com/oauth/authorize?app_id="your app_id"&redirect_uri=https://www.google.com/&scope=user_profile,user_media&response_type=code

After hitting above API in web-view I got bellow new URL with code in it:

http://www.google.com/?code=AQCPw4m0jd85IX7Qi83rd-pxsFKDE8Bjb0kZ2pWZ8sarcPlNyaZXwzE1yHHqfVIgDej_ZPYrTh6_BaIafsOWsTZNJbWFDiXsQPTEZHvFBojQ5F91SBSykqjUkG0U1OS6nFyAcwNq-FsbpmBtIPcp45qNXV5_avgCCpBzG-Hndp6JiRbaF2uSgUiOep5-Uu0Ks8DiwVs_7zAfuMasJJ7PAK1gfRDNVOPC-XBYqfdPU1VlkA

In this example my code is

AQCPw4m0jd85IX7Qi83rd-pxsFKDE8Bjb0kZ2pWZ8sarcPlNyaZXwzE1yHHqfVIgDej_ZPYrTh6_BaIafsOWsTZNJbWFDiXsQPTEZHvFBojQ5F91SBSykqjUkG0U1OS6nFyAcwNq-FsbpmBtIPcp45qNXV5_avgCCpBzG-Hndp6JiRbaF2uSgUiOep5-Uu0Ks8DiwVs_7zAfuMasJJ7PAK1gfRDNVOPC-XBYqfdPU1VlkA

I use it in access_token request below:

https://api.instagram.com/oauth/access_token?
app_id="YOUR APP ID"
&app_secret="YOUR SECRET KEY"
&grant_type=authorization_code
&redirect_uri=https%3A%2F%2Fwww.google.com%2F
&code=AQCPw4m0jd85IX7Qi83rd-pxsFKDE8Bjb0kZ2pWZ8sarcPlNyaZXwzE1yHHqfVIgDej_ZPYrTh6_BaIafsOWsTZNJbWFDiXsQPTEZHvFBojQ5F91SBSykqjUkG0U1OS6nFyAcwNq-FsbpmBtIPcp45qNXV5_avgCCpBzG-Hndp6JiRbaF2uSgUiOep5-Uu0Ks8DiwVs_7zAfuMasJJ7PAK1gfRDNVOPC-XBYqfdPU1VlkA

Response of above api hit:

{
    "access_token": "IGQVJVT2hod1dEN3N0UnBwTWllb3pZAaENnS0VveHZARSkNwLVpwS2Uxc0w2VUVOeEJxaUdkMnlQRkdzVGJudnh0cXREZA3BvWHNELTR1UndsOWR2MXFST0JlUG45TEdFVnhiblhScVNlYlJtLUNwQU5Kc2ltZAy1LUlRMaF9ZA",
    "user_id": 17841406439718884
}

Now in order to get User Profile data, I am hitting bellow api using above access_token as mentioned in link :

Api hit :

https://api.instagram.com/v1/users/self/?access_token="+accesstoken

But in this api, I am getting error which says:

{
    "meta": {
        "code": 400,
        "error_type": "OAuthAccessTokenException",
        "error_message": "The access_token provided is invalid."
    }
}

But when I use Access-Token Debugger from Graph api explorer, It shows me the token is valid by displaying information about my created application:

https://developers.facebook.com/tools/debug/accesstoken/?access_token=IGQVJWSHA1NF9ZAVGxGaTlyclRtLUl1SmE4YkdPSjVzTUdWNl94VjBuSDYybzBkRUJiZAlN4djFBRkVXVTJHT2U4bTRabjc3T1FLU0hWekx1TkljUnZAMOVBjdGFUdmtjZAHpTTl91cW5TNWlETjJBYS10MXVqQ3lxUVRGNDRJ&version=v5.0

I even tried with bellow url inorder to get valid accessToken:

https://www.instagram.com/oauth/authorize/?app_id="your app id"&redirect_uri=https://www.google.com/&response_type=token

But it gives me:

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid response type: token"}

I found one website which provide me instagram access-token:

https://instagram.pixelunion.net/

This token is returning me the data of my user:

Now url : https://api.instagram.com/v1/users/self/?access_token=6311078657.1677ed0.c249ea5b413c4f59b6768c0ad20d7cbb

Response: {"data": {"id": "6311078657", "username": "xolomss", "profile_picture": "https://scontent.cdninstagram.com/vp/de42466846f4a5942832321f5f2c547c/5E71495A/t51.2885-19/s150x150/26226680_188125481777380_3421501291661099008_n.jpg?_nc_ht=scontent.cdninstagram.com", "full_name": "Xolo Mss", "bio": "", "website": "", "is_business": false, "counts": {"media": 0, "follows": 4, "followed_by": 1}}

But am confused that then what is the use of all above steps? As mentioned in this link

After using above accessToken I am always getting information regarding xolo (Might be because at time of generating accesstoken using that link i was loggedin as xolo in instagram web)regradless of from which ID i am getting logged in, Please let me know how to get accessToken programmaically , I have clearly mentioned every step I follow if you stil need anything for more calrification I willprovide you that too!!!



from OAuthAccessTokenException-The access_token provided is invalid Instagram new api

No comments:

Post a Comment