Facebook API - How do I create an ad account? - facebook

I am currently trying to create an ad account using fb's api. After checking out their documentation I ended up with this source. Here it states that we can make a call to
/{business_id}/adaccount given the appropriate body to create an ad account, and therefore I went to give it a try.
On my test, I tried sending a POST request to that endpoint:
POST {FB_API_PATH}/{business_id}/adaccount?access_token={FB_ACCESS_TOKEN}
BODY
{
"name": "Test",
"currency": "USD",
"timezone_id": 1,
"end_advertiser": "{FB_APP_ID}",
"media_agency": "{FB_AGENCY_ID}",
"partner": "NONE",
"funding_id": "{FB_FUNDING_ID}"
}
but ended up getting:
Unsupported post request. Object with ID '{business_id}' 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.
This is not because I'm using an incorrect {business_id}, all of my other test calls that are using the same {business_id} are working perfectly.
It seems to me that for some reason, I cannot make a call to /adaccount. I went to check the facebook graph explorer and wasn't able to get the autocomplete trigger for that endpoint when inputing the {business_id}.
Am I doing something wrong, or was this endpoint never working and I need to keep doing it manually?

You need to have Advanced Access to business_management permission.
You can submit app review for advanced access, if it approved, you can call /bm-id/adaccount to create ad account with required parameter.

Also, you can't create an ad account on a real FB user. It works with test users well, but you need special permissions from FB to do this on a real user's account.

Related

Unsupported get request. Object with ID 'XXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation

I want to use User Profile API from Facebook to get customer user data (first name, last name, picture). My app is reviewed, my app is connected to fanpage, i have pages_messaging and other permissions active. Webhooks are working correct, i receive messages from user and i can respond to them, yet when i use PSID from webhook and use it on this endpointhttps://graph.facebook.com/v9.0/{PSID} i get this error:
"error": {
"message": "Unsupported get request. Object with ID 'XXXXX' 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}
Am I missing some permissions? Bad app/page configuration? I've been trying to find something in documentation but right now i'm defeated by it.
I solved the problem with getting additional permission Business Asset User Profile Access (api 8.0+).
I had the same issue, one probable reason is that you need to pass the account ID with 'act_' at the beginning of it so it becomes 'act_XXXXX'.
I was having the same issue, the main reason is that you need to pass the account ID starting with
'act_'
at the beginning
of it so it becomes
'act_XXXXX'
This resolved my issue. Hope so resolves everyone's who is coming to find solution for it.
Looks like you cannot make this request on behalf of Test User. If it is your case, try to make a call from Tester's Role user account instead.
For real life application you need Business Asset User Profile Access
There can be multiple reasons to it, you need to check the status of your account by visiting the Alerts Page on this url: https://developers.facebook.com/apps/<APP_ID>/alerts/inbox/?business_id=<BUSINESS_ID>
This alert page would show you the issue/permissions denied, for example:

"PERMISSION_DENIED" on Google Spreadsheet REST API v4

I try to read data from google sheet via http. I use v4 google spreadsheet api:
https://sheets.googleapis.com/v4/spreadsheets/1MZJEOzkzy5iJ9HPy2GU-Ky3vdaIzGGDQH8BMt4n3OGI/values/Sheet1!A1:D5
I get:
{
"error": {
"code": 403,
"message": "The request cannot be identified with a client project. Please pass a valid API key with the request.",
"status": "PERMISSION_DENIED"
}
}
Sheet is published online and everyone can edit it. It works on api v3 too.
First, make sure you have a permission to call this spreadsheet and you enable the Sheets API in your developer console. You can also try to change the privacy settings of this spreadsheet to public and checked if you can access it now. This 403 error is usually caused by incorrect or missed some configuration in Authorizing Requests. If you authorizing requests with OAuth 2.0, make sure you use the proper scope with it.
For more information, you can check this thread on how to debug your Google OAuth 2.0 token when you get HTTP 401s or 403s
You have to append the string "key=yourAPIkey" as query on your URI. The API key is generated in the developer's console
If you update application access scope you have to re-authenticate the application and update credentials.json.
In google-sheet quick start guide, they have started the tutorial with only read scope. If you want to write or update google-sheet later you will have to change the scope there and update the credentials.json again
Look carefully when you first authenticate it only giving permission to read. But if update scope and try to re-authenticate it will ask for permission to read and manage sheet permission.
In order to update the scopes, you need to remove the token file saved in TOKENS_DIRECTORY_PATH, execute the code again and log in. Then Oauth2 will give you the new updated tokens.

API authentication from a facebook messenger bot conversation

What is the best way to authenticate with an external API from a conversation with a bot on the facebook messenger platform?
For a broad example, I would like a user of my bot to create items on their own profiles of an external website. Is there a way to get login information from the user, or connect my bot to the external website, without the user explicitly sending a message to the bot with their username and password?
What I found in the documentation under User Profile API:
You can personalize the conversation using the person's name or profile pic from the User Profile API. In order to get this information, make a GET request to https://graph.facebook.com/v2.6/?fields=first_name,last_name,profile_pic&access_token=. Read more details in the Send API reference.
This isn't quite what I'm looking for but it helps. Here's more info from the docs:
User Profile API
Request
curl -X GET "https://graph.facebook.com/v2.6/<USER_ID>?fields=first_name,last_name,profile_pic&access_token=<PAGE_ACCESS_TOKEN>"
Response
{
"first_name": "Peter",
"last_name": "Chang",
"profile_pic": "https://fbcdn-profile-a.akamaihd.net/hprofile...70ec9c19b18"
}
It depends how they come in.
If they come from your website, you can use the Send to Messengee button from within their account. Use the pass through param to link your account to the user thread.
Here's an excerpt from the documentation:
The plugin takes in a pass-through parameter defined by you. This parameter is sent back to you via a callback. You can use this to link the authentication event to a person and/or transaction. For example, a person may enter an online flow for a specific transaction and click the Send-to-Messenger button. You can pass in data to know which user and transaction was tied to the authentication event. You should encode and encrypt this parameter.
If they come directly to your bot, you would have to present them with a login of some sort (your login) from within the conversation. This would happen in a link to an mobile web URLs.

product catalog api fail

need help.
I tried to start with https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/ads-management/v2.3
created account. Approved it by phone.
created a business account, an ad account, an app, and so on.
linked app to ad accont like this https://developers.facebook.com/docs/marketing-api/access#standard_accounts.
Now i tried to create product catalog. i am getting same error all the time:
The app is not whitelisted to use this API
i tried to call api to cteate/list/managment product catalog.
when i did, the same by UI - i can create product catalog & feed.
but by API - all time error.
i do not understand what it need?
now try to create product set:
GET /<product_catalog ID>/product_sets/?
access_token=<my access token from app with full rights get from exploer>
{
"error": {
"message": "(#200) The app is not whitelisted to use this API",
"type": "OAuthException",
"code": 200
}
}
try to create the same:
POST : /v2.3/<product_catalog ID>/product_sets/?access_token=<my access token from app with full rights get from exploer>&name=my new prod set
{
"error": {
"message": "(#275) Ad account cannot be determined for this request",
"type": "OAuthException",
"code": 275
}
}
So what Are the changes i needed to make it work?
is it any way to made api calls work correctly?
p.s.
i guess something wrong in settings - i run unit tests in SDK - have the same situation. i have read about that problems with game app - but my app - is not a game, so i cant use solution in my situation.
if some body understand what whitelist API want - please help!
Thanks.
Hopefully this helps someone else: I was also trying to create a Product Catalog via the API in Development, and got "The app is not whitelisted to use this API".
I solved it by creating an admin system user, and generating an access token with the business_management permission.
The error is explained by the documentation you linked to - unless your app is approved for Standard access to the API it can only access a specific number of ad accounts and those accounts need to be pre-configured in the app settings
Many of the business manager APIs can't be used because they're not tied to one of those pre-specified accounts (hence the Ad account cannot be determined for this request error).
In general, the business manager APIs likely won't work for you until your app has access at the standard level, though some will if they're account-specific
You can't be an app admin and a tester/developer at the same time. You should create another facebook account for tests.
This happens also when the access token used is not from your app which has Standard Access. Also, note the dev version of the same app will not work.

Facebook graph api returns no email

I'm calling
https://graph.facebook.com/<user_id>/?access_token=<valid_token>
or just
https://graph.facebook.com/me/?access_token=<valid_token>
and getting back json object that doesn't contain primary user email which I need.
I setup email permission for the app and no effect.
What can be wrong?
Did you remember to ask for the email permission in the login request? You do this by adding the scope parameter like this in the login request (&scope=email):
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_REDIRECT_URI&state=SOME_ARBITRARY_BUT_UNIQUE_STRING&scope=email
Facebook API reference
You probably do not have email permissions in your access token.
You can verify it with the Acess Token Debugger
I believe that your question is, even after granting permission to access email, you are not able to get email information through the Graph API. In newer versions, you need to pass fields param to the API to get additional information such as email. By default, it only provides id and name in response. Please find a sample below on how to get other info from graph :
https://graph.facebook.com/me?fields=id,email,first_name,gender,last_name,link,locale,name,timezone,updated_time,verified&access_token=<value of access_token>&debug=all
Hope this helps.
It is possible that the email is not verified in facebook. In this case facebook doesn't make it available via the API. Make sure your code handles this case.
Since the release of API version 2.5 you can get user email like this: https://graph.facebook.com/v2.5/me?fields=id,name,email