facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.27k stars 629 forks source link

[New Pages Experience] #652

Closed amzar96 closed 9 months ago

amzar96 commented 10 months ago

Facebook Python Business SDK Issue

I am coming from here. However, I'm not sure whether this repo is cover the new Page or not?

Just1B commented 9 months ago

Hi amzar96,

This repository contains all the method to create, update & request objects in the api ( AD_ACCOUNTS, PAGES, IG_USERS, VIDEOS etc ... ).

For example, if you are trying to know if a page has_transitioned_to_new_page_experience, you can request this information with the graph request below.

ex : {PAGE_ID}?fields=id,name,has_transitioned_to_new_page_experience

https://github.com/facebook/facebook-python-business-sdk/blob/main/facebook_business/adobjects/page.py#L4809

Regards

amzar96 commented 9 months ago

Understand it is achievable using graph request. But from facebook_business.adobjects.page import Page let's say I am using this method, how to get fields=id,name,has_transitioned_to_new_page_experience these?

Just1B commented 9 months ago

The snippet below should do the job for you 👍

You can check in the examples directory for more use cases : https://github.com/facebook/facebook-python-business-sdk/tree/main/examples

from facebook_business.adobjects.page import Page
from facebook_business.api import FacebookAdsApi

access_token = '<ACCESS_TOKEN>'
id = '<PAGE_ID>'

FacebookAdsApi.init(access_token=access_token)

fields = [
  'id',
  'name',
  'has_transitioned_to_new_page_experience'
]

print(Page(id).api_get(fields=fields))
amzar96 commented 9 months ago

Got it, thanks @Just1B . Just know that it doesn't support date range.

Thanks

Just1B commented 9 months ago

Depends on the type of data your are requesting, if you want to get page insights it does.

https://github.com/facebook/facebook-python-business-sdk/blob/main/facebook_business/adobjects/page.py#L2303

from facebook_business.adobjects.page import Page
from facebook_business.api import FacebookAdsApi

access_token = '<ACCESS_TOKEN>'
id = '<PAGE_ID>'

FacebookAdsApi.init(access_token=access_token)

fields = [ ... ]

params = { 
  'date_preset' = '<YOUR_PRESET>
}

print(Page(id).get_insights(fields=fields, params=params))