GithubHelp home page GithubHelp logo

Comments (9)

victorarthur avatar victorarthur commented on April 20, 2024 1

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.

paulbain avatar paulbain commented on April 20, 2024

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.

cornernote avatar cornernote commented on April 20, 2024

Ok, makes sense. Thanks for clarifying.

from facebook-php-business-sdk.

bnamnguyen avatar bnamnguyen commented on April 20, 2024

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.

cornernote avatar cornernote commented on April 20, 2024

hey @bibibaonam,

It's explained here:
https://developers.facebook.com/docs/reference/ads-api/overview#access_token

from facebook-php-business-sdk.

cornernote avatar cornernote commented on April 20, 2024

here is my quick guide:

  1. 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/

  2. 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.

paulbain avatar paulbain commented on April 20, 2024

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.

paulbain avatar paulbain commented on April 20, 2024

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.

bnamnguyen avatar bnamnguyen commented on April 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.