Comments (9)
Hi @paulbain
I have the same issue, I would like to clone the AdCreative (to rename the url_tags and this parameter doesn't available on the /copies node) so I have do download the object and recreate with a different url_tags parameter. In advance, I don't know what fields does the AdObject has so I can not pre-define the fields I would request.
Do you know any solution for this issue?
from facebook-php-business-sdk.
This is expected behaviour. You should only request the fields from the API that you need as it decreases load and increases performance.
You also cannot read all possible fields of an object. Some fields can only be used when writing.
You can set the default fields to read on an object once which you may want to do if you always read the same fields.
Sent from my iPhone
On Dec 3, 2014, at 2:23 AM, cornernote [email protected] wrote:
I try to read an AdCreative like this:
Api::init($app_id, $app_secret, $access_token);
$adCreative = new AdCreative($ad_creative_id, $account_id);
$adCreative->read();
print_r($adCreative->getData());
But it results in:Array
(
[id] => THE ID
[title] =>
[actor_id] =>
[actor_name] =>
[name] =>
[object_id] =>
[object_story_id] =>
[object_story_spec] =>
[body] =>
[image_hash] =>
[image_file] =>
[image_url] =>
[image_crops] =>
[video_id] =>
[actor_image_hash] =>
[link_url] =>
[object_url] =>
[url_tags] =>
[preview_url] =>
[follow_redirect] =>
[object_store_url] =>
[link_deep_link_url] =>
[call_to_action_type] =>
[object_type] =>
)
I then try using $adCreative->getFields() as an argument to $adCreative->read():Api::init($app_id, $app_secret, $access_token);
$adCreative = new AdCreative($ad_creative_id, $account_id);
$adCreative->read($adCreative->getFields());
print_r($adCreative->getData());
Which throws an exception:Array
(
[message] => (#100) Tried accessing nonexisting field (image_file) on node type (AdCreative)
[type] => OAuthException
[code] => 100
)
I then remove image_file from the list of fields:Api::init($app_id, $app_secret, $access_token);
$adCreative = new AdCreative($ad_creative_id, $account_id);
$fields = $adCreative->getFields();
foreach ($fields as $k => $v) {
if ($v = 'image_file') {
unset($fields[$k]);
}
}
$adCreative->read($fields);
print_r($adCreative->getData());
Which results again in no data:Array
(
[id] => THE ID
[title] =>
[actor_id] =>
[actor_name] =>
[name] =>
[object_id] =>
[object_story_id] =>
[object_story_spec] =>
[body] =>
[image_hash] =>
[image_file] =>
[image_url] =>
[image_crops] =>
[video_id] =>
[actor_image_hash] =>
[link_url] =>
[object_url] =>
[url_tags] =>
[preview_url] =>
[follow_redirect] =>
[object_store_url] =>
[link_deep_link_url] =>
[call_to_action_type] =>
[object_type] =>
)
I try making my own fields array, and then remove any that cause an exception, and end up with this list:Api::init($app_id, $app_secret, $access_token);
$adCreative = new AdCreative($ad_creative_id, $account_id);
$fields = array(
AdCreativeFields::ID,
AdCreativeFields::TITLE,
AdCreativeFields::ACTOR_ID,
AdCreativeFields::ACTOR_NAME,
AdCreativeFields::NAME,
AdCreativeFields::OBJECT_ID,
AdCreativeFields::OBJECT_STORY_ID,
AdCreativeFields::OBJECT_STORY_SPEC,
AdCreativeFields::BODY,
AdCreativeFields::IMAGE_HASH,
//AdCreativeFields::IMAGE_FILE,
AdCreativeFields::IMAGE_URL,
AdCreativeFields::IMAGE_CROPS,
AdCreativeFields::VIDEO_ID,
AdCreativeFields::ACTOR_IMAGE_HASH,
AdCreativeFields::LINK_URL,
AdCreativeFields::OBJECT_URL,
AdCreativeFields::URL_TAGS,
//AdCreativeFields::PREVIEW_URL,
//AdCreativeFields::FOLLOW_REDIRECT,
AdCreativeFields::OBJECT_STORE_URL,
AdCreativeFields::LINK_DEEP_LINK_URL,
AdCreativeFields::CALL_TO_ACTION_TYPE,
AdCreativeFields::OBJECT_TYPE,
);
$adCreative->read($fields);
print_r($adCreative->getData());
Now I get what is expected (i have replaced the actual data incase of any security issue sharing it):Array
(
[id] => THE ID
[title] => AD TITLE
[actor_id] => THE ACTOR ID
[actor_name] =>
[name] => AD NAME
[object_id] =>
[object_story_id] =>
[object_story_spec] =>
[body] => AD BODY
[image_hash] => IMAGE HASH
[image_file] =>
[image_url] => https://fbcdn-creative-a.akamaihd.net/REMOVED-PATH.png
[image_crops] =>
[video_id] =>
[actor_image_hash] =>
[link_url] =>
[object_url] => http://www.example.com/
[url_tags] =>
[preview_url] =>
[follow_redirect] =>
[object_store_url] =>
[link_deep_link_url] =>
[call_to_action_type] =>
[object_type] => DOMAIN
)
My question is, is this the expected behaviour? Or should I be able to do $adCreative->read() without specifying a field list?—
Reply to this email directly or view it on GitHub.
from facebook-php-business-sdk.
Ok, makes sense. Thanks for clarifying.
from facebook-php-business-sdk.
hi cornernote,
where can I get $access_token to put into Api::init($app_id, $app_secret, $access_token); ?
thank you very much
from facebook-php-business-sdk.
hey @bibibaonam,
It's explained here:
https://developers.facebook.com/docs/reference/ads-api/overview#access_token
from facebook-php-business-sdk.
here is my quick guide:
-
get the AUTHORIZATION_CODE from the URL after going here:
https://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&scope=ads_management&redirect_uri=http://yourdomain.com/ -
get the access token from the URL after going here:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=https://yourdomain.com/&client_secret=YOUR_CLIENT_SECRET&code=AUTHORIZATION_CODE
from facebook-php-business-sdk.
Please don't share access tokens publicly. That's a quick way to get your account into a lot of trouble.
You should consider changing your FB password to invalidate the token you just shared, or uninstalling the app from your FB settings.
from facebook-php-business-sdk.
To answer your question, prefix the account ID with act_ like in all the examples:
$account = new AdAccount('act_<YOUR ACCOUNT ID>);
$fields_you_want_to_read = array('name');
$adaccount = $account->read($fields_you_want_to_read);
echo $adaccount->name;
from facebook-php-business-sdk.
Thank you very much Paulbain.
I removed app from my account https://www.facebook.com/settings?tab=applications
Your reply worked, tks again.
from facebook-php-business-sdk.
Related Issues (20)
- getDefaultRequestHeaders() is misspelled as getDefaultRequestHeaderds() HOT 1
- PHP 8.1 Deprecation HOT 4
- syntax error, unexpected '|', expecting ';' or '{' HOT 4
- Union types are only allowed since php8 HOT 2
- Exception: field 'id' is required Error HOT 2
- شخص ما أخترق حسابي الشخصي
- Normalizer.php strlen() must be of type string Problem
- Facebook Multi-Language Ads
- Syntax error in FB version v16.0.0 HOT 1
- The AdAccountFields enum does not currently implement the ACCOUNT_STATUS field. HOT 1
- Exception thrown without a stack frame in Unknown on line 0 HOT 1
- How to create a AAA advertisements above version 17
- Fix package installation instructions in README file
- Fff HOT 1
- error
- ad creative Url Tracking Params Update HOT 1
- OpenSSL SSL_connect: Connection reset by peer in connection to graph.facebook.com:443 Error
- Static singletons used everywhere HOT 3
- Incorrect PHPDoc types HOT 2
- Not able to access Business User Insights for multiple users using the Instagram API.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-php-business-sdk.