How to get users' FB Ad Account Id via API? - facebook

I can get my own ad account id via a curl requests to
https://graph.facebook.com/v2.8/me?fields=id%2Cname%2Cadaccounts&access_token=
We have Ads Management Basic Access permissions from Facebook.
I have also tried https://developers.facebook.com/docs/graph-api/reference/user/adaccounts/
Both get the same error.
{ error:
{ message: '(#3) Application does not have the capability to make this API call.',
type: 'OAuthException',
code: 3,
fbtrace_id: 'HiXZVS8UeI8' } }
What is the endpoint to get user Ad accounts? What permissions do I need?

The page you link to lists
Managing advertisements requires an access token with the extended
permission for ads_management
You can test in the Graph API Console when you generate a new token

Related

How can I get an instagram business account with Facebook Graph API?

The condition I am using:
Graph API version: 7.0
The problem I have: I can get the Instagram business account of my Facebook developer account,
However, I cannot get the Instagram business account when I login Facebook with another account.
The account has the permissions below:
The Instagram account is connected to its Facebook page.
The Instagram account is a business profile.
The Facebook account that I want to connect to Instagram account has the authorisation more than editor.
I could get this:
/me?fields=name,picture, but not
/me/accounts?fields=instagram_business_account
I tried with this API:
/me/accounts?fields=instagram_business_account{name,username,profile_picture_url},access_token,name,picture{url}', function(response) { }
The response I got:
{ "data": [ ] }
Do I need additional authorisation or something?
Your App is most likely not public and and you need to go through the review process first - with all the permissions you need. Else, it will only work for users with a role in the App.
More information: https://developers.facebook.com/docs/apps/review/
Also, the IG account must be a business account, and it must be connected to the Facebook Page: https://www.facebook.com/business/help/898752960195806
To get Instagram IDs linked to user's pages you need these permissions (verified and approved for your app): instagram_basic, pages_show_list, pages_read_engagement.
You can read guide here https://developers.facebook.com/docs/instagram-api/getting-started
Everything is correct on that page except extra permission needed to get IG ID: pages_read_engagement

Get group events as a system user with Facebook API

I have a website which should list all the events from my facebook group. So I created a facebook dev account and created an app.
When I tried to get the data with the graph API explorer it worked, but the access token expired after a few hours. So I had to get a never-expiring access token.
I created a sytem user at the facebook business manager. With the system user I got a never-expiring access token but I couldn't get the event data anymore. Everytime I tried it I got this response.
"Unsupported get request. Object with ID 'xxxxxxxxxxxxx' 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"
I have the following permissions as system user:
read_insights, read_audience_network_insights, manage_pages, pages_manage_cta, pages_show_list, publish_pages, business_management
Why did it fail? Are the permissions correct?
Thanks for your help.

Get user profile link from Facebook's Graph API

I have an app-scoped user id (ASUID) for a Facebook user and I wish to obtain a link to that user's profile page.
A post on Facebook's Developer blog dated May 1, 2018 states that this link is accessible as of Graph API v3.0 through the link field on a user object. Access to this field requires the user_link permission be approved for the app and granted by the app user.
I have attempted to access this field with a user access token associated with my test app and I have verified the access token has the user_link permission granted via the Access Token Debugger. However, the link is not included in the response.
Request:
https://graph.facebook.com/v3.0/[ASUID]?fields=link&access_token=[ACCESS_TOKEN_W_USER_LINK_PERMISSION]
Response:
{ "id": "[ASUID]" }
Is there any indication as to why this is not working?
As documented, the user_link permission requires an App Review pass before it's available to live apps.
At time of writing this answer there is no way to get user profile page using Facebook API.

Facebook Graph API throws "User is not admin or developer of this application" exception Error #272

We are building a Facebook app to feed custom audiences from our system. Our clients will login via Facebook and with the token we got we need to manage their ad accounts to upload custom audiences.
We followed these steps:
created a Facebook app.
added Facebook login to our web app with this scope:
'ads_management,manage_pages,business_management'.
collected token from an user who is not the administrator of our
Facebook app.
via Graph API fetched the ad accounts list of the user.
called v2.12/act_{0}/customaudiences?access_token={1}&fields=description.
When we try to reach custom audiences Graph API returns the JSON below:
{
"error": {
"message": "(#272) This Ads API call requires the user to be admin of the application. User is not admin or developer of this application.",
"type": "OAuthException",
"code": 272,
"fbtrace_id": "B+lKfUAU320"
}
}
What we are doing wrong? Why API returns this exception?
Thanks.

Facebook: App Access token, Posting to a User

I went through this wonderfull tutorial on Using App Access token. According to this post it says that:
If the user has not provided the appropriate permissions to publish on the user’s behalf, you will receive an error message. For example, if the user has not provided the publish_stream permission, the following error will be returned:
{
"error": {
"message": "(#200) The user has not granted the application the permission to automatically publish feed stories",
"type": "OAuthException",
"code": 200
}
}
Now is there any other way to post to a users wall who has not authorized the app?
My query is this:
I have two logins for my app, one Login with Email and other FB Connection. So a user may login with email or facebook to my app. If he logs in with facebook there is no problem at all as i have his access token. If he login with email , then i don't have his user access token, so in this case i want to use the App Access token to fetch the users friends and then allow him to post to friends wall [friends who are not a member of our app / not authorized our app].
there is no way to post to a user wall who has not authorized the app.
one possible soln:
you have to link up the user login via the email and fbID
stored the access token when the user accesses your app via fbID
if the user login via the email, then get the access token from local storage and use it for the posting.