Facebook Graph API permission issue - node.js

I have a problem with querying the Facebook Graph API and reading with extended permissions. I want to query a page's latest posts with additional data for a reporting dashboard (show the number of likes, reactions and post impressions) I have an express app with passport-facebook running in order for the user to authenticate and provide the permissions in question. This setup used to work before, but now I am experiencing a strange problem.
This is what I am requesting: created_time,link,full_picture,message_tags,with_tags{link},message,reactions.summary(true),insights.metric(post_impressions)
I had my app in Facebook's review process and they granted me the read_insights permission for querying insights.metric(post_impressions). After the review I was able to pull all the data I needed from the API. That was 2 weeks ago. Today I experienced the problem that I can only pull very limited data out of the API. The response keeps giving me Permission error (OAuthException), stating "User doesn't have enough permissions to load insights", "You do not have enough permission to view the metric."
However, when I add the limit and/or the after params to the query I do get data back, but only with very low values for limit (that is <= 5, but after 2 paginated requests, no subsequent requests are allowed) or a value for after, which I don't have for an inital request.
Has there been a change to the API (couldn't find anything in the changelog)? Maybe I'm just overlooking something trivial?
Thanks!

Since nobody else (not here or anywhere else I asked for help) seemed to have experienced the issue I filed a bug at Facebook and it turned out to be an individual problem with some item(s) on my page's feed. Here's their response:
This is a particular issue with one or more specific posts from that page feed, that is causing the entire call to fail when trying to include it.
This issue might be addressed in a future version of Graph API. There are two workarounds for now: either use a page access token or if sticking with a user access token, giving it granular permissions to the pages.
I've tried option 1 and a page access token seems to fix the issue.

Related

invalid/missing permissions trying to read leadgen data in webhook Facebook Graph API

I use the version 9.0 of the Grapph API. The leads retrieval was wroking ok, but the last 3 weeks I am not able to retrieve lead form information, using the endpoint :
https://graph.facebook.com/v9.0/${leadId}/?access_token=${process.env.FACEBOOK_PAGE_ACCESS_TOKEN}
The page access token as well as the facebook app has all the permissions like leads_retrieval, pages_manage_ads, pages_manage_metadata, pages_read_engagement, business_management, public_profile, pages_show_list.
When I create a lead form id from the page that is connected to the app, and then use the testing tool (https://developers.facebook.com/tools/lead-ads-testing) to check if the webhook works, everything works ok !!
The facebook and the connected page that are connected and were used for testing purposes, do belong in different businesses.
The problem is that when someone submits a lead from paid campaigs, then the following error message shows:
An invalid response was received from the Facebook API: {"error":{"message":"Unsupported get request. Object with ID '1223289864932223' 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":"AIQ5Q-yJo249IZwdn10dfhi"}}
Is there an error in the set up of the whole system? Something that needs to be changed? Why suddenly did it stop working ?

How can I get my app using Instagram Basic Display API pass app review?

This is now the 4th time I am sending my app for review. I want to use Instagram Basic Display API and therefore require instagram_graph_user_media permission to access media (and incidentally instagram_graph_user_profile). I have 2 test users, my personal IG account with a bunch of pics and a test user that I created with an empty feed. I can login with both users. But when the Instagram app reviewer is logging in, my app can't access their media. I successfully retrieve the access token but when comes the time to call the Graph API here is what happens:
https://graph.instagram.com/me/media?fields=media_type,media_url,permalink,thumbnail_url&access_token=IGQV....
returns
{"error":{"message":"Application does not have permission for this action","type":"IGApiException","code":10,"fbtrace_id":"A99vuaAC41DSvlt0Hxvcly-"}}
Here is an update from my latest app review rejection. This time, I added the code above to catch code 10 errors and if I did, try to fetch the user profile data. Guess what, that failed with a code 10 error as well. So, whatever the app reviewer is doing, it is granting access to neither the profile or the media API.
Another update. The reviewer I had this time sent me two screenshots, one of the Instagram login screen and one of my app's error screen. Interestingly, the Instagram login screen had a strange Instagram username that I have never heard of before. It certainly wasn't my test Instagram account. So I now have evidence of them both using my test account and their own special test accounts.
The question in my mind now is, is there something special about their test accounts that ruins the process? After all, I have not added them to be testers of my app, although if someone who hasn't accepted my test invite tries to log in, it errors in an entirely different way.
I am running out of ideas here. My next thing to try is to exchange the short-lived access token for a long-lived token, as well as trying to use the new access token to server-side (where I exchange the code for the access token) to check if the access token ever works or if it is created with insufficient access.
This whole process is a nightmare.
I will put this as an answer because we have dealt with this thing now for over 2 weeks and quite a few submissions. I think you should remove the bounty though.
What you have done so far:
Created and approved IG test accounts
Double and triple checked parameters & permission
Tested your app a dozen times
Created dozens of screencast spoon-feeding, making sure a 5 yo kid would be able to test your app
Having the above, I am sure you noticed:
The reviewer will add a generic text as 'reject reason.'
The reviewer will submit the irrelevant and out-of-scope screenshot(s)
The reviewer will not test with the Instagram credentials provided.
Maybe he WILL test with the Instagram test credentials provided (in fact you're left in the dark as to how they actually simulate IG access)
The reviewer will claim he's unable to sign in using provided credentials
The reviewer claims having tested, but you see no traces in your DB whatsoever (would be smart to do so, to know whether they're actually doing something or not, up to a certain point)
Conclusion
You have to know that your app is at the reviewer's mercy and approval sometimes arbitrarily. Eventually, you will find your app being approved while having submitted it to change at all.
This should be obvious but when you are so deep in the hole and try to think why your app is being rejected you stop thinking logically.
Here is what I did:
Create a dummy Instagram account.
Link this account to an email provider that doesn't require a phone/another way of verification (I used ProtonMail).
Use an Instagram Tester account (do the whole process).
In your instructions let the reviewer that they need to log in to ProtonMail to get the Instagram confirmation code; since they will do login from an unknown location (if you could simulate the above in your screencast that would be great, but I didn't do it).
If you apply for both instagram_graph_user_profile and instagram_graph_user_media you need to do this in 2 steps individually.
The second step getting the instagram_graph_user_media permission is much easier.
I lost a couple of days and tried everything and anything before I realized that.
Hopefully, this should help someone that is having the same problem.
The app was approved the first time.
It is possible that the App Reviewer is unchecking the instagram_graph_user_media access in the authentication screen, thus giving you only access to instagram_graph_user_profile. I had the exact same error code being thrown back my way, and I did the following:
Catch the error code 10 error
Try to fetch the https://graph.instagram.com/me?fields=account_type,username&access_token=${accessToken}
If that works, then display a page that makes it clear that you have successfully connected to the Instagram User Profile (and here is your username and account type) but, if the user wants to do X they also need to approve media access, and here is a button to go and reauthenticate again.
See the image I have below.
Now, I did the above and I still got an app review failure of code 10, which means that the second fetch to only the username and account type failed, and I do not know how they could possibly have managed to do that.
They admitted issue but not fixed yet: https://developers.facebook.com/support/bugs/543633182940083/
To get approved for Instagram Basic Display:
create a Facebook test user
create an Instagram account with that FB test user
give the credentials (email/address) of the Facebook test user to the reviewer in the Instagram Basic Display submission
Basic Display API review process is so bad its beyond words. I have been hitting the brick wall of their rejections for 3 weeks and almost got bald by pulling my hair in frustration. You really have to read between the lines to get a hint of what they are doing.
Turns out what the reviewer was doing is selecting "Continue with Facebook" on the Instagram Login screen and going that route (via Facebook login) instead of entering the instagram credentials directly. Only once I realized that I was able to pin point the problem. Interestingly though testing on the Simulator was fine but the problem only became apparent once I tested on the real device. The reason - simulator doesn't have neither Facebook app nor Instagram app installed, so it behaves differently versus the device where these apps get involved in the flow via deep linking.
The bottom line:
Test on real device.
Make sure to test both the direct Instagram log in and the "Continue with Facebook" option.
Test on the device with and without the Facebook and/or Instagram app installed.
Make sure to use brand new instance of WKWebView with non persistent data store to bring up the login screen, so that it doesn't have any cookies from previous logins:
let configuration = WKWebViewConfiguration()
configuration.websiteDataStore = WKWebsiteDataStore.nonPersistent()
let webView = WKWebView(frame: .zero, configuration: configuration)
Pray the God of your choosing.

Instagram search user api always return empty result with success code

We are invoking instagram search users api to get profile list as
https://api.instagram.com/v1/users/search?q={search-term}&access_token={access-token}
but we are getting always empty result with success code as
{"meta": {"code": 200}, "data": []}
Our search term would be always instagram username i.e. username portion from https://www.instagram.com/username/
I remember this was working before 2-3 months. Any other are facing similar issue?
Sounds like you already figured out your problem. In case anyone else is having the same problem, here's a short article summarizing how Instagram's Sandbox Mode works.
TL;DR
“Sandbox mode” is the (unintuitively-named) gatekeeper walling off
most of what you want to do. This is the default status for all
clients, that have not undergone the strict submission process. An API
client in sandbox mode has extremely limited permissions. In fact, it
has fewer permissions than an anonymous user viewing public content
because your app basically lives on a tiny desert island in which you
are the only Instagram user and only your past twenty posts exist. So,
for example, the /media/search endpoint will only return the media you
uploaded near a given location, excluding the media from everyone else
or any posts beyond your last twenty.
So your API call is succeeding. It just isn't finding any results because it can only "see" other sanbox users for your client.

Instagram API throwing OAuthAccessTokenException 400 error using client id

I was using the following api to get the latest 3 posts from public accounts to show on the website:
https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3
I had created an app to get the client-id.
However from today, this API has started throwing the following exception:
{
meta: {
error_type: "OAuthAccessTokenException",
code: 400,
error_message: "The access_token provided is invalid."
}
}
Could you please let me know as how to resolve this?
Based on the date, you probably have an older app that got hit by the API migration today, like mine. In short, Instagram decided to make developing for their platform WAY more annoying by requiring all API requests to be authenticated per user, even for data that users shares publicly. So you (like me) will likely be redesigning you app entirely.
To tell, log in to instagram.com/developer and click manage clients; then hit edit next to the set of keys your're trying to use. Up near the top, it will have a section called 'Client Status' -- if yours reads 'Sandbox Mode', fun times ahead! Hopefully you interact with less than 10 users and can stay in sandbox mode, otherwise you'll have to write an essay, film a video, and basically plead to get your permissions back (probably in a few months, when some Instagram intern finally digs his way down to you in the pile of applications). If it reads something eles, you've got another problem altogether and should thank your lucky stars.
In the meantime, I guess I'll get back to sending out dozens of emails to the maintainers of our many, many affiliated Instagram accounts to explain the issue and try to get permissions, so provided we get approved by then, all our social media displays aren't broken during a huge event Saturday. Another option might be to use the OAuth-less json response available here, but that might break terms of service.
I have a solution to this. If you are using the same code I am, which appears likely. I was pulling the last two images using this.
https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3
What I did to get this working is the following.
Login to your Instragram account you are using as the application.
Go to the developer (API) area. https://www.instagram.com/developer/clients/manage/
Manage clients. Make sure your website URL is the same as your valid redirect URL.
Add new Sandbox User. Put in the account of the IG photos you want to reach.
Hit this URL: https://api.instagram.com/oauth/authorize/?client_id=CLIENTID&redirect_uri=REDIRECT_URI&response_type=token where the client ID is the same one you used in your previous app above.
You should get back and access token URL. Copy your access token.
Login as your account that you want the IG photos of. The account you added as a sandbox user and go to developer and approve the Sandbox Invites.
Change your original URL above from https://api.instagram.com/v1/users/{user-id}/media/recent/?client_id={client-id}&count=3 to https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS_TOKEN with your access token.
This is the IG API Media endpoint documentation: https://www.instagram.com/developer/endpoints/users/
After that, it all worked for me and while you are in the sandbox, you should be able to pull the last 3 photos or at this point, figure out how to read the JSON to do so.
Has your app been approved after the June 1st Instagram platform changes?
http://developers.instagram.com/post/145262544121/instagram-platform-update-effective-june-1-2016
If you want to retrieve the user media file then try this, It's working for me
https://graph.instagram.com/me/media?fields=id,caption,media_url,media_type&access_token=ACCESS_TOKEN
For some reason the token is no more valid. Request it again.
Possible reasons why a token is no more valid:
changed password
verified the account
logged-in from a different country

cannot access followers on instagram sandbox

I'm trying to test my Instagram app in sandbox, I'm trying to get some stats and alerts on new/lost followers ... but is not possible because of sandbox limitations; followers to the authAccount are hidden. I understand I cannot access accounts out of sandbox as main accounts, but I should be able to check ALL followers and followings.
Please Instagram team fix this!
I want to test pagination, but this is impossible because of sandbox limits.
As it is set now,
https://api.instagram.com/v1/users/self/follows?access_token=XXX&count=100
returns just an empty result
It's not broken, this is by design.
You need two things:
Include follower_list as one of the scopes when you authenticate
Add some users to your Client's Sandbox
Once you have the appropriate scope and a few users in your client's sandbox you can have the sandbox users follow each other. Queries generated by a sandboxed client will return only users that you manually added to the sandbox.
It's kind of confusing but that's what got me going.
Probably it because of sandbox limitation, recently faced smth similar http://progrnotes.blogspot.co.uk/2015/11/instagram-api-search-by-tag-doesnt.html.
I think you need to have test users in folowers, and you will be able to see them via api
It's due to the fact that you're in Sandbox mode. I can't see it either. You'll need to apply for the permissions starting December 3 to gain access to the followers list scope.
I think there actually is an issue. Even with correctly configured OAuth permissions in sandboxed mode!
Today, there are several endpoints that deals with followers.
self/follows
Example:
https://api.instagram.com/v1/users/self/follows?access_token=ACCESS-TOKEN
self/followed-by
https://api.instagram.com/v1/users/self/followed-by?access_token=ACCESS-TOKEN
Now, obviously the API uses the access-token to get the proper information. So, the only list it can return here is the list of users that the current authenticated user follows or is followed by.
In the previous API, there was an API endpoint that looked like this
/users/[user-id]/follows?access_token=ACCESS_TOKEN
This endpoint is still valid but works exactly the same as self/follows and self/following, that is, only useful for the current authenticated user. That is, in-sandboxed-mode! Will post if I can get passed the find folks at the Instagram review board. (This is I guess the only way to properly test this.) However, there are no documentation of this use of the API so it may very well not work.
This leaves us with the following API endpoints:
{user-id}/relationship
Example
v1/users/{user-id}/relationship?access_token=ACCESS-TOKEN
Again, this will obviously only return the status of the relationship between the currently authenticated user and the user with the user-id supplied in the url.

Resources