Invalid parameter in Facebook marketing API - facebook

$video_data = new AdCreativeVideoData();
$video_data->setData(array(
AdCreativeVideoDataFields::VIDEO_ID => $videoId,
AdCreativeVideoDataFields::CALL_TO_ACTION => array(
'value' => array(
'page' => '209938349531555',
),
),
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => '209938349531555',
AdCreativeObjectStorySpecFields::VIDEO_DATA => $getId,
));
$creative = new AdCreative(null, 'act_101365637166818');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$crtv=$creative->create();
This is the code I am using to for video ad.But I am getting this error:
"Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter'"

Do you initialize API?
Api::init(
'<app_id>',
'<app_secret>',
'<facebook_access_token>'
);
In AdCreativeObjectStorySpec set data you have error
AdCreativeObjectStorySpecFields::VIDEO_DATA => $getId
change to:
AdCreativeObjectStorySpecFields::VIDEO_DATA => $video_data
Do you have linked Facebook app with the Facebook site?
Page Subscribed Apps
You don't have call to action type
'type' => AdCreativeCallToActionTypeValues::LIKE_PAGE,
Read Docs Ad Creative Video Data

Related

Facebook Marketing API - Ad Creative not generating properly

I'm working on a script to generate Facebook ads through the API. For some reason the variables for the ad creative are not being added to the ad. The main issue is the title and body are not being added. Here's the code I have for generating the ad creative:
try{
$creative = new AdCreative(null, $accountId);
$creative->setData(array(
AdCreativeFields::NAME => $ad_info['Ad Name'],
AdCreativeFields::TITLE => $ad_info['Title'],
AdCreativeFields::BODY => $ad_info['Body'],
AdCreativeFields::IMAGE_HASH => $image->hash,
//AdCreativeFields::OBJECT_URL => $ad_info['Preview Link'],
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
AdCreativeFields::URL_TAGS => $ad_info['URL Tags'],
));
$creative->create();
echo 'Creative ID: '.$creative->id . "\n";
}
catch (Exception $e) {
echo '<pre>creative';print_r($e);exit;
if($e->getMessage()){
echo 'Error message: ' .$e->getMessage() ."\n" . "<br/>";
}
//echo 'Error Code: ' .$e->getCode() ."<br/>";
}
And the code for adding the creative to the ad:
$ad = new Ad(null, $accountId);
$ad->setData(array(
AdFields::CREATIVE =>
array('creative_id' => $creative->id),
AdFields::NAME => $ad_info['Ad Name'],
AdFields::ADSET_ID => $adsetId,
AdFields::STATUS => 'ACTIVE',
AdFields::TRACKING_SPECS => array('action.type' => $ad_info['action type'], 'fb_pixel' => $fb_pixel),
));
$ad->create();
It's not throwing errors, and the other variables, such as ad name, status, etc. all appear to be added to the ad correctly. As near as I can tell all of the above is correct according to Facebook's API documentation. I even tried throwing a sleep function in between the creative being generated and adding it to the ad. What could the issue be?
I figured out what the issue is. The ad creative object isn't applied to an ad if it's a link ad, which the ads this script is generating are. In order to get things like the the title and body text to appear, you have to add them in the AdCreativeLinkData like so:
$link_data->setData(array(
AdCreativeLinkDataFields::DESCRIPTION => $ad_info['Link Description'],
AdCreativeLinkDataFields::LINK => $ad_info['Link'],
AdCreativeLinkDataFields::NAME => $ad_info['Title'],
AdCreativeLinkDataFields::MESSAGE => $ad_info['Body'],
AdCreativeLinkDataFields::IMAGE_HASH => $image->hash,
AdCreativeLinkDataFields::CALL_TO_ACTION => array(
'type' => AdCreativeCallToActionTypeValues::SIGN_UP,
'value' => array(
'link' => $ad_info['Link'],
'link_caption' => $ad_info['Link'],
),
),
));
Once I added the NAME and MESSAGE variables to this object, the title and body of the ad showed up perfectly.

Cant Create Facebook Ad via Ads API

I am trying to create a Facebook AD via their PHP SDK. The problem lies in the creation of the ad itself. If I comment out the last piece, its creates the adset. When I run this code, I get the error "a Parent ID is required"
try {
///////////////////////////// CREATE AD SET ////////////////////////////////////
$data = array(
AdSetFields::NAME => $adname,
AdSetFields::BID_TYPE => 'CPC',
AdSetFields::BID_INFO => array(
'CLICKS' => 6,
),
AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_PAUSED,
AdSetFields::DAILY_BUDGET => 500000,
AdSetFields::CAMPAIGN_GROUP_ID => $campaign_id,
AdSetFields::TARGETING => array(
'age_min' => 30,
'age_max' => 45,
'page_types' => array(
'desktopfeed',
),
'geo_locations' => array(
'countries' => array(
'US',
),
),
),
);
$adset = new AdSet(null, $account_id);
$adset->create($data);
$adset_id = $adset->id;
echo $adset_id.'-';
//////////////////////CREATE AD IMAGE ///////////////////////////////
$image = new AdImage(null, $account_id);
$image->{AdImageFields::FILENAME} = '../adimages/epsom.jpg';
$image->create();
$creative = new AdCreative(null, $account_id);
$creative->setData(array(
AdCreativeFields::TITLE => $adtitle,
AdCreativeFields::BODY => $addesc,
AdCreativeFields::OBJECT_URL => $tracking_promoted_url,
AdCreativeFields::IMAGE_HASH => $image->hash,
));
$creative->create();
echo $creative->id.'-';
/////////////////////////////// CREATE AD GROUP ////////////////////////////
$fields = array(array(
AdGroupFields::CREATIVE =>
array('creative_id' => $creative->id),
AdGroupFields::ADGROUP_STATUS => AdGroup::STATUS_PAUSED,
AdGroupFields::NAME => 'My First AdGroup',
AdGroupFields::CAMPAIGN_ID => $adset_id,
));
$ad = new AdGroup();
$ad->create($fields);
echo 'AdGroup ID:' . $adgroup->id . "-";
} catch (RequestException $e) {
echo 'Caught Exception: '.$e->getMessage().PHP_EOL
.'Code: '.$e->getCode().PHP_EOL
.'HTTP status Code: '.$e->getHttpStatusCode().PHP_EOL;
}
You're missing the parent ID parameter when you create the adgroup. The 2nd parameter should be the account ID you want to create this adgroup under:
$adgroup = new Adgroup(null, $accountId);
If you copied this from a doc, let me know and we can update.
You may reference to the latest doc: https://developers.facebook.com/docs/marketing-api/reference/ad-campaign
From there, you will need to specify the ad account id(AD_ACCOUNT_ID) and ad campaign id(CAMPAIGN_GROUP_ID)

Using Graph API to create an event with map

I am adding a new event via the graph API.
Is there a secret to making the map appear or does it has to be an official FB place?
This is what i am sending. Everything seems to work (kindof)
A couple of things.
When i view the event, no zip or map are displayed.
Any help/suggestions would be greatly appreciated
BTW all the fields are populated and correct
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true,
'fileUpload' => true
));
$fb->setAccessToken($_SESSION[ $eid.'_FB_USER_ACCESSCODE' ]);
$data = array( 'access_token' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'owner' => $_SESSION[ $eid.'_FB_USER_ACCESSCODE' ],
'latitude' => $event->getLat(),
'longitude' => $event->getLong(),
'name' => $event->getTitle(),
'description' => $description,
'start_time' => date('c', $event->getStart()),
'end_time' => date('c', $event->getEnd()),
'street' => $event->getAddress(),
'city' => $event->getCity(),
'state' => $event->getState(),
'zip' => $event->getZip(),
'location' => $event->getLocation(),
'privacy' => 'OPEN'
, basename($fileName) => '#'.$fileName
) ;
I'm not sure, but the map what you see isn't just an image?
The event documentation says: https://developers.facebook.com/docs/reference/api/event/ you able to submit the event's profil picture.

Facebook API access outside of apps.facebook.com

I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}

Zend_Feed_Reader Not supported Schema

I'm using Zend FW and wanted to make a feed reader. I did the following:
$feed = Zend_Feed_Reader::import('feed://blog.lookup.cl/?feed=rss2');
$data = array(
'title' => $feed->getTitle(),
'link' => $feed->getLink(),
'dateModified' => $feed->getDateModified(),
'description' => $feed->getDescription(),
'language' => $feed->getLanguage(),
'entries' => array(),
);
foreach ($feed as $entry) {
$edata = array(
'title' => $entry->getTitle(),
'description' => $entry->getDescription(),
'dateModified' => $entry->getDateModified(),
'authors' => $entry->getAuthors(),
'link' => $entry->getLink(),
'content' => $entry->getContent()
);
$data['entries'][] = $edata;
}
And it throws the following exception: Scheme "feed" is not supported
The blog was made using Wordpress.
What's wrong? If "feed it's not supported", how can I change the type of feed that Wordpress does?
Thanks in advance,
Take care,
Solved.
I had to put http instead of feed.