facebook ads api - read other account campaigns - facebook

I am using Facebook ads api to read campaign from other account. I have created the application, got app_id and app_secret. In graph explorer, I am using other person's access token and account id to get his campaigns. But facebook gives me following error:
{
"error": {
"message": "(#274) The ad account is not enabled for usage in Ads API. Please add it in developers.facebook.com/apps -> select your app -> settings -> advanced -> advertising accounts -> Ads API. Account 1817273581872129 not enabled for this application.",
"type": "OAuthException",
"code": 274,
"fbtrace_id": "GW38TMsIi1v"
}
}
I did followed error instructions but still the same problem.
here is the url i am using in graph explorer:
act_12345566654/campaigns
However, when I use facebook ads api in python:
I get the following error:
FacebookRequestError:
Message: Call was not successful
Method: GET
Path: https://graph.facebook.com/v2.8/act_1817273581872129/campaigns
Params: {'summary': 'true'}
Status: 400
Response:
{
"error": {
"message": "Invalid appsecret_proof provided in the API argument",
"code": 100,
"type": "GraphMethodException",
"fbtrace_id": "FRdlngO8f04"
}
}
Here is the code:
session = FacebookSession(self.app_id, self.app_secret, self.access_token)
ads_api = FacebookAdsApi(session)
adaccount = AdAccount(self.account_id, api=ads_api)
campaigns = adaccount.get_campaigns()
Where am I going wrong ? Kindly assist me

Most likely, the app secret that you have provided doesn't belong to the app id or the access token that you are using doesn't belong to the right app.
Check the following:
1) The app id
2) The app secret (should be of the specific app)
3) The access token (should be for the app specified above)

In case you still need it - in the explorer you must haven't selected the app. This is on the top right corner. By default, it sets the app to Graph Api Explorer, click on the drop down menu, and choose your actual app.
Cheers!

Related

Facebook ID Matching API says invalid token

I have an app in firebase where the user logs in with Facebook. From that login I get his ASID. Now I want to get this users ID in my messenger and write him a message.
I followed this tutorial: https://developers.facebook.com/docs/messenger-platform/identity/id-matching
My URL looks something like this:
https://graph.facebook.com/v5.0/{ASID}/ids_for_apps?access_token={pageAccessToken}&appsecret_proof={sha256}
To get the pageAccessToken:
https://graph.facebook.com/v5.0/{pageId}?fields=access_token&access_token={userAccessToken}
Now I get this error:
{
"error": {
"message": "(#100) Invalid token. Can only query using page access tokens where the page is owned by the same business as the app.",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "ACv6_We47HagGtMBzrQuT5A"
}
}
Does anyone know what I am doing wrong?
In the developer page for my App, I have linked the sites (Settings > Extended > App Pages)

Can you get a page access token for a page you do not own, ie you are a third party ? (FB insights)

Would like to use these FB Graph API insights endpoints for the Nike FB page.
https://developers.facebook.com/docs/graph-api/reference/v2.12/insights
But, every time I go to the developers.facebook.com tools and generate a new "Page Access Token" and then try to type in the endpoint, I get this error:
{
"error": {
"message": "(#190) This method must be called with a Page Access Token",
"type": "OAuthException",
"code": 190,
"fbtrace_id": "CWg3K5qBxk+"
}
}
Page Tokens are for Page owners only. Think about it this way: Would you be able to get access to Google Analytics of some website you do not own? Of course there is also no way to access the Facebook Insights of a Facebook Page you do not own.
I believe you cant get access to info insights.
However you can get some info from the API
For instance:
'Nike?fields=fan_count,pharma_safety_info,phone,description'
returns:
{
"fan_count": 32788277,
"description": "Just Do It. ",
"id": "15087023444"
}

Facebook Graph API (Post with Photo Ids) - (#10) Application does not have permission for this action

I'm trying to publish a post on my wall with two photos as attachments using Graph API Explorer.
Here's what i did:
I have selected all permissions in my user access token, and am using v2.5.
I have previously uploaded a photo to the endpoint: /me/photo and in response i got its id. i.e. "10154656374686756". This id will remain active for the next 24 hours.
Then I'm passing the photo id as a parameter (that i got in step 2) to my post using endpoint: /me/feed like this:
Graph API Explorer - Post Request
But in response i'm getting the following error instead of the newly created post id:
{
"error": {
"message": "(#10) Application does not have permission for this action",
"type": "OAuthException",
"code": 10,
"fbtrace_id": "BzOCZ1z3tUH"
}
}
I can't figure what i'm doing wrong here. Your help will be much appreciated.

How to get the result in Facebook Graph Api Explorer.? Getting error message (#15) This method must be called with an app access_token

I was Unable to get the search result in Facebook Graph Api Explorer For Topic search API. I am getting the following error. I also have the access token included.
{
"error": {
"message": "(#15) This method must be called with an app access_token.",
"type": "OAuthException",
"code": 15,
"fbtrace_id": "CJiZqVSATXu"
}
}
Well, the error message actually contains the problem. You're not using an App Access Token, but seemingly an User Access Token (from the Access Token structure in your screenshot).
You must select an app of yours in the upper right Applications dropdown, and then select Get App Token in the dropdown below.
Still, that will probably not help much in this case. Are you aware that only whitelisted apps can use the Topic Search API?
See
https://developers.facebook.com/docs/graph-api/using-graph-api#search
https://developers.facebook.com/docs/mediasolutions/topic_search/v2.5

Create a Link Ad for a Facebook object (event url)

In business manager it's possible to create a Link Ad with a Facebook Event url. I like to do the same with Facebook Ads API but facing a permissions error.
The Ad Creative of an Ad created in business manager looks like this one:
{
"object_story_spec": {
"page_id": "24188824589????",
"link_data": {
"link": "https://www.facebook.com/events/25595316793????/",
"message": "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"image_hash": "cbb1f226fd5fe47c826dd1cad117????"
}
}
}
When I am trying to create the same Ad Creative via Ads Api I get an error message like the following:
{
"error": {
"message": "Invalid parameter",
"type": "FacebookApiException",
"code": 100,
"error_subcode": 1349118,
"is_transient": false,
"error_user_title": "Disallowed Post Link",
"error_user_msg": "One or more of the given URLs is not allowed by the Stream post URL security app setting. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains. Read https://developers.facebook.com/docs/facebook-login/security/ to learn more about app settings related to security."
}
}
I get the same error if I try to create a Link Post with Graph API separately to use as object_story_id.
We really need this kind of Ads for our business. In stream ads perform much better than display ads. Is there anyway to create ads like this one via Ads API?
You should check the migration settings for your app to see if "Steam post URL security" is enabled.
This prevents URLs being posted by your app which do not link to a domain listed in your app settings.