Specifying a FB Page for a desktop/mobile news feed ad using Python SDK - facebook-graph-api

I'm new to the Facebook Ads Python SDK and am trying to create an ad that will display on mobile and desktop news feeds. Reviewing the web flow to create an ad, to show up in a feed, the ad needs to be related to a Facebook page. I manage a Facebook page, but am not sure where I need to input the FB page info.
I've reviewed the documentation and getting started examples, however the getting started is about a page post ad, so not relevant to me. I assumed "Placements" would be relevant but nothing I find there is helpful either. I also looked at Connection objects but that also seemed a dead end.
The code I've got runs and creates ads that are right column ads. I've tried adding "page_types: ['feed']" to AdSet targeting but that returns an error saying that placement is ineligible for this ad.
Could someone point me in the right direction on how to create an ad that will show up in the desktop news feed? Meat of the code is below.
`
# create campaign
campaign = AdCampaign(parent_id=config['act_account_id'])
campaign[AdCampaign.Field.name] = 'Test Campaign'
campaign[AdCampaign.Field.status] = AdCampaign.Status.paused
campaign[AdCampaign.Field.objective] = AdCampaign.Objective.website_clicks
campaign.remote_create()
# create adset
targeting = {
#'page_types': ['feed'],
'geo_locations': {
'cities': [{'key': '2532348', 'radius': 25, 'distance_unit': 'mile'}]
}
}
data = {
AdSet.Field.name: 'My Python SDK AdSet',
AdSet.Field.bid_type: AdSet.BidType.cpc,
AdSet.Field.is_autobid: True,
AdSet.Field.status: AdSet.Status.active,
AdSet.Field.lifetime_budget: 500,
AdSet.Field.end_time: '2015-06-4 23:59:59 PDT',
AdSet.Field.campaign_group_id: config['campaign_id'],
AdSet.Field.targeting: targeting,
}
adset = AdSet(parent_id=config['act_account_id'])
adset.remote_create(params=data)
# Set up creative for ad
image = AdImage(parent_id=config['act_account_id'])
image[AdImage.Field.filename] = image_filename
image.remote_create()
creative = AdCreative(parent_id=config['act_account_id'])
creative[AdCreative.Field.name] = 'sample creative'
creative[AdCreative.Field.title] = 'ad headline'
creative[AdCreative.Field.body] = 'ad text'
creative[AdCreative.Field.object_url] = 'www.http://www.misc-url.com'
creative[AdCreative.Field.image_hash] = image[AdImage.Field.hash]
creative.remote_create()
# Create your ad by referencing the ad creative.
adgroup = AdGroup(parent_id=config['act_account_id'])
adgroup[AdGroup.Field.name] = 'Testing SDK Ad'
adgroup[AdGroup.Field.campaign_id] = config['adset_id']
adgroup[AdGroup.Field.creative] = {'creative_id': str(creative_id)}
adgroup[AdGroup.Field.status] = AdGroup.Status.paused
adgroup.remote_create()
`

There is an api call to create a page post at the time of ad creation:
https://developers.facebook.com/docs/marketing-api/adcreative/v2.3#object_story_spec
See the blog post for more detailed info:
https://developers.facebook.com/ads/blog/post/2014/08/28/creative-page-post-api

Related

Python Google API Campaign Manager inserting creative asset is showing success, but isn't appearing in advertiser

I'm using the campaign manager API to upload a local file into an advertiser; the script works all the way through without any errors. However, when checking the advertiser directly, there isn't a new creative asset. The changelogs also don't show any new changes. The script run (without the google authentication - OAuth 2.0, which is working to expectation on other calls):
def upload_creative_asset(
service, profile_id, advertiser_id, asset_name,path_to_asset_file,
asset_type):
"""Uploads a creative asset and returns an assetIdentifier."""
# Construct the creative asset metadata
creative_asset = {
'assetIdentifier': {
'name': asset_name,
'type': asset_type
}
}
media = MediaFileUpload(path_to_asset_file, mimetype='image/gif')
if not media.mimetype():
media = MediaFileUpload(path_to_asset_file, 'application/octet-stream')
response = service.creativeAssets().insert(
advertiserId=advertiser_id,
profileId=profile_id,
media_body=media,
body=creative_asset)
return response
path_to_creative = "automated_dcm_loading/test.gif"
upload_creative_request = upload_creative_asset(service,advertiser_id='10229XXX',profile_id='6414XXX',asset_name='test.gif',path_to_asset_file=path_to_creative,asset_type='image')
upload_creative_request.execute()
The response is:
{'kind': 'dfareporting#creativeAssetMetadata',
'assetIdentifier': {'type': 'IMAGE', 'name': 'test.gif'},
'id': '475828XXX',
'richMedia': False}
This tells me it's worked but doesn't appear in campaign manager anywhere.
UPDATE: This is only half the process to get an asset to appear in campaign manager. The next step for those who need this is to use this exact output in a creatives().insert() function to wrap the asset with a creative. Without this creative step your asset/image/video will sit on a server somewhere with nowhere for it be shown.

Error Pulling Facebook Ad Campaign

I am trying to automate a task for my company. They want me to pull the insights from their ad campaigns and put it in a CSV file. From here I will create a excel sheet that grabs this data and automates the plots that we send to our clients.
I have referenced the example code from the library and I believe where my confusion exists is in who I define 'me' to be in line 14.
token = 'temporary token from facebook API'
VOCO_id = 'AppID'
AppSecret = 'AppSecret'
me = 'facebookuserID'
AppTokensDoNotExpire = 'AppToken'
from facebook_business import FacebookSession
from facebook_business import FacebookAdsApi
from facebook_business.adobjects.campaign import Campaign as AdCampaign
from facebook_business.adobjects.adaccountuser import AdAccountUser as AdUser
session = FacebookSession(VOCO_id,AppSecret,AppTokensDoNotExpire)
api = FacebookAdsApi(session)
FacebookAdsApi.set_default_api(api)
me = AdUser(fbid=VOCO_id)
####my_account = me.get_ad_account()
When I run the following with the hashtag on my_account, I get a return stating that the status is "live" for these but the value of my permissions is not compatible.

How to get Facebook ad permalink using Facebook APi

When using ads manager, you can preview ad. There is also a hyperlink which goes View post permalink with comments. Is there any way to get that link using API
First you must get the creative that's targeted by the ad.
$ad = new Ad($ad_id);
$ad->read(array(
AdFields::CREATIVE,
));
Then get the info from the creative.
$creative = new AdCreative($ad->creative['id']);
$creative->read(array(
AdCreativeFields::EFFECTIVE_OBJECT_STORY_ID,
));
Then $creative->effective_object_story_id will contain an ID that would look like xxxxxxxxxxxxx_yyyyyyyyyyyyy, where x is the ID of the page, and y is the id of the post/video/etc.
If you just go to https://facebook.com/xxxxxxxxxxxxx_yyyyyyyyyyyyy it should redirect you to the correct post
Hope this helps someone.

Commerce Server with Sitecore - how to update orders status

May I ask how to update orders status with Sitecore Commerce 8 powered by Commerce Server. Or in sitecore 7.2 if possible.
Based on the class Sitecore.Commerce.Connect.CommerceServer.Orders.Models.CommerceOrder class, we tried to save StatusCode as "InProcess" but it was not updated.
CartServiceProvider provider = new CartServiceProvider();
var orderRequest = new SubmitVisitorOrderRequest(buyCart);
var orderResult = orderService.SubmitVisitorOrder(orderRequest);
var order = orderResult.Order as CommerceOrder;
order.StatusCode = "InProcess";
provider.SaveCart(new SaveCartRequest(order));
We have tried the code below but got an error.
https://social.msdn.microsoft.com/Forums/en-US/a4e74c33-cf4f-4a1b-843c-acf2514db3f2/how-to-update-purchase-order-status?forum=commserver2009#44ff5a5e-b6af-4b82-aebe-1c53beff9f5c
We modified the code to update status as admin
OrderSiteAgent orderAgent = new OrderSiteAgent("website", true, "");
Error : on line OrderManagementContext context = OrderManagementContext.Create(ordersAgent);
There was a problem reading the site resources from the Commerce Server administration database for the site 'website'. Please check that resources exist for the site and that the process has permission to access the database. The InnerException contains more details.

facebook create_event posts on my app's wall not the user's wall

i'm attempting to provide a facility on my site that allows a user to create a facebook event for their booking.
http://developers.facebook.com/docs/reference/api/event/
now im doing the correct process:
1) first getting authorisation from the user
https://graph.facebook.com/oauth/authorize?client_id=APP_ID&redirect_uri=http://urlimredirectingto.comtype=web_server
2) requesting for an access token with the "code" that is returned in step 1
https://graph.facebook.com/oauth/access_token
3) using the access_token to create the event ...
string facebookCreateUri = string.Format("https://graph.facebook.com/{0}/events", loggedInMember.FacebookUID);
var formData = new HttpUrlEncodedForm()
{
{"access_token", accessToken},
{"owner", loggedInMember.FacebookUID},
{"description", "nice event that should be on the owners wall"},
{"name", "event on the users wall"},
{"start_time", "1272718027"},
{"end_time", "1272718027"},
{"location", "rochester"},
{"privacy","OPEN"}
};
HttpContent content = HttpContent.Create(formData);
HttpClient client = new HttpClient();
var response = client.Post(facebookCreateUri, "application/x-www-form-urlencoded", content);
but the event is posted on my app's wall, not the user's wall. It shouldn't have anything to do with the authentication/access_token elements because i use the same process to post on the user's wall. (http://developers.facebook.com/docs/reference/api/status/) and that works just fine.
I came back with a solution, after a week of working at many features with Facebook SDK, it finally works!
protected void onPostEvent(object sender, EventArgs e)
{
if (CanvasAuthorizer.Authorize())
{
var fb = new FacebookWebClient(CanvasAuthorizer.FacebookWebRequest);
dynamic parameters = new ExpandoObject();
parameters.description = txtEvDett.Text;
parameters.name = txtEvName.Text;
parameters.start_time = DateTime.Now.ToString("yyyyMMdd");
parameters.end_time = DateTime.Now.AddDays(1).ToString("yyyyMMdd");
parameters.access_token = CanvasAuthorizer.FacebookWebRequest.AccessToken;
dynamic eventDet = fb.Post("me/events", parameters);
litEvent.Text = String.Format("You have created the event with ID: {0}", eventDet.id);
lnkEvent.Visible = true;
lnkEvent.NavigateUrl = String.Format("http://www.facebook.com/event.php?eid={0}", eventDet.id);
}
}
For events, you have to request the create_event permission.
You should use /me/events to post on your events.
I user the C# SDK for Facebook from Codeplex - last version available for dld (aug 2011 - v5.2.1).
Good luck!
I don;t see in your request for Authorization any permission.. base permissions are not enough to do the postings.
i used:
https://www.facebook.com/dialog/permissions.request?app_id=MY_APP_ID&next=MY_APP_URL&display=page&response_type=code&canvas=1&perms=publish_stream,user_about_me,email
This is in the context of a canvas app. where MY_APP_URL is the url from facebook of the app:
http://apps.facebook.com/MY_APP_NAME_OR_ID
See extended permissions for events and check event's page in documentation
[EDIT] - I came back, sorry, now i did a test, and indeed, it works for me, but only of i post on my app's wall; even if i provided the 'user_events' permission i get this error:
The remote server returned an error: (403) Forbidden when posting on a user's wall.
This being said, i also subscribe to this question.