How to get access token from Instagram API - swift

I've been following Instagram's basic guides here https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-access-tokens-and-permissions
I added my personal Instagram account as a tester and I got the authorization code, but when I send the request to get the access token, this is my response:
{
"error_type": "OAuthException",
"code": 400,
"error_message": "Missing required field client_id"
}
This is my input in POSTMAN:
Any help or possible tips will greatly be appreciated, thanks in advance!

I found the solution to my own question here Impossible to get an access_token for Instagram Basic Display API
When using Postman for Instagram's API, you should fill out the info required under the POST request's Body, NOT the Parameters. And when in the body, just select x-www-form-irlencoded

Just a clarification, you also have to keep "#_ at the end of the code for it to work (contrary to what the doc says)

Related

Instagram Graph API unusual error during GET request for insights

I am trying to extract instagram insights data to further analyze it locally and store it. For that I generated a system user access_token with the required permissions. Now I am trying to perform a GET request just as described in this documentation: https://developers.facebook.com/docs/instagram-api/reference/ig-user/insights
For that my call URL looks like this:
https://graph.facebook.com/v15.0/{instagram-id}/insights?metric=impressions,reach,profile_views&period=day&access_token={system_user_token}
This gives following response:
{
"error": {
"message": "(#100) The value must be a valid insights metric",
"type": "OAuthException",
"code": 100,
"fbtrace_id": xxx }
}
Thinking maybe this is due to my system user token not beeing elegible for this call I tried the Graph API explorer in the browser and a generated access token with the needed permissions. I am not quite sure where to go from here. Thank you for your help
I tried different access_tokens generated in the business manager and also generated in the meta for developers website. I tried to use a variety of different metrics described in the documentation. All gave the same output as described above. I also tried different api versions (15.0 and 16.0)

Permission issue when publish comment with Facebook Graph API v2.12

I am testing the facebook graph API comments
https://developers.facebook.com/docs/graph-api/reference/v2.12/object/comments
I checked my permission for the access token it contains the permission, which required by API. see the screenshot
I test my object-id (1797963943566411_1975256375837166) which is correct see me screenshot
Change the request method to POST and adding post data {"message": "haha"}
I get the error message shows:
"(#3) Publishing comments through the API is only available for page access tokens" see my screenshot
As you can see the first step checking, I have all the permission that the
API required.
Can any one see any sort of error in this process?
Try another way still not work.
I have a user who post a photo on his own facebook page.
I logged in with this user and give this user all permissions see the screenshot
enter image description here
call /me/accounts to get page access token
enter image description here
copy the page access token into the Graph API Explorer's access token field
call
GET: 1797963943566411_1975256375837166/likes
is working fine
But call POST: 1797963943566411_1975256375837166/likes
Get error response:
{
"error": {
"message": "(#200) Permissions error",
"type": "OAuthException",
"code": 200,
"fbtrace_id": "GtEaBfyXrUD"
}
}
The reason is Facebook changed the API behaviour. We are no longer to use api to like any POST on our time line. API can only like or comments on facebook page. Sad face !!!!

Facebook API error subcode 33

I have an app that gets leads from facebook after webhook request when leads fill out forms: Some pages are throwing this error:
{
"error": {
"message": "Unsupported get request. Object with ID '233332620530416' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "HIItB4mggfk"
},
"__debug__": {}
}
I cannot find the error subcode description in Facebooks API docs.
Check you access token at https://developers.facebook.com/tools/debug/accesstoken
Your app might be missing a needed permission scope.
Visit Business Settings > Users > System Users > Chose «Conversions API System User» > Add Assets. Add your Pixel with ID from your request to the list of assets System User can access.
I have had this issue a few times and the error led me to spend an hour or two combing the docs. The real issue for me each time has been malformed json in the request body (I'm using curl). Dumb I know, but in case a poor soul comes across this. Be sure to validate your json before you decide you query is wrong.
I got this error when adding access_token in post body, worked when adding parameters to url.
Success result using postman
Not success result using postman
Add your access token in the Authorization tab, then choose Oauth2.0 and add your access token on the right side. Please refer to the screenshot for the postman.Click here for the screenshot
I found the answer recently
Follow this steps using postman
https://graph.facebook.com/page-name/feed
headers:
Content-Type: application/x-www-form-urlencoded
Body:
message: "your message"
link:"your web link "
access_token:'Your access token '

Posting on user's timeline on the behalf of the user

I created and APP on the Facebook.
Now I am trying to post a comment on the user's timeline using the Graph API but I cannot undestand what I need to do.
I already authorized the Application (I authorized this permissions: 'user_status,publish_stream,user_photos,email').
If I look on my profile -> privacy I can see that the APP can:
This app can: Post on your behalf
This app may post on your behalf, including status updates, photos and more.
Last data access:
Basic InformationToday
See details · Learn more
Posts on your behalf:
Who can see posts this app makes for you on your Facebook timeline?
Public
Notifications:
When to notify you?
The app sends you a notification
So this part seems OK.
On my application I do the following to try to post somenthing on my timeline (I need to post it when I am off line).
1) GET : https://graph.facebook.com/oauth/access_token?client_id=APPID&client_secret=*APP_SECRET*&grant_type=client_credentials
RESPONSE:
access_token = 422828347771671|UdQELQIf0N7krF4JUo7VwtPLTkk
2) GET: https://graph.facebook.com/search?q=myemail&type=user
RESPONSE:
_"error":_{
______"message":_"A_user_access_token_is_required_to_request_this_resource_",
______"type":_"OAuthException",
______"code":_102
___}
But reading the documentation (https://developers.facebook.com/docs/reference/api/#searching) it seems that this request does not need any kind of access token.
I also tried to add the access token, but the result is still the same.
3) I know my facebookid so I tried to use it directly:
POST: https://graph.facebook.com/100001139132403/feed
ARGUMENT:
access_token=422828347771671|UdQELQIf0N7krF4JUo7VwtPLTkk,
message=Hello
RESPONSE:
"error": {
"message": "(#200) This API call requires a valid app_id.",
"type": "OAuthException",
"code": 200
}
}
So I tried to add client_id=APPID and app_id=APPID, I tried to put one, the other and also both arguments as GET or POST but nothing changed.
I checked the APPId ad it is correct.
Do someone have any idea?
Thank you!
You cant simply generate a user access_token by querying to a URL. What you did gives the App access token and as the error say, you are trying to do something, that needs user access_token.
Refer and implement this : https://developers.facebook.com/docs/howtos/login/server-side-login/
And use that access_token for the rest of the processes.

Facebook acheivment registeration error

i try to register an achievement for my game app thorough Graph API Explorer using a POST to https://graph.facebook.com/APP_ID/achievements with access_token =xxxxxx ,achievement = right url and display_order =1 but it throws the following error
{
"error": {
"message": "(#15) This method must be called with an app access_token.",
"type": "OAuthException",
"code": 15
}
}
. i have checked the achievment url and my app access token in the object debugger and it gives right result. But still im getting the above when try to register my achievement. i have checked evrywhere i could to find a solution but didnt get any (although there where similar post which didnt a give solution). Any help will be much much appreciated as it really takes my lot of time figuring out a solution
Are you sure it's the app access token retrieved from the instructions at https://developers.facebook.com/docs/authentication/applications/ and not the user's access token?
If you're doing this with the Graph API Explorer instead of in code or manually, you need to replace the access token the Graph API explorer is using with the one you retrieved via those instructions