I have the following code to generate a facebook post for a page using graph api.
$page_info = $facebook->api("/$pageId?fields=access_token");
if (!empty($page_info['access_token'])) {
$attachment = array(
'access_token' => $page_info['access_token'],
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$status = $facebook->api("/$pageId/feed", "post", $attachment);
Posts from one of my facebook pages look like below image.
link to image - How my posts look
Then i came across some other pages, whose posts look like below image. As you can see, these preview images are large and appear above the post. When we click them, we are redirected to another website's page. So i had to assume, we are not posting this as image. Please note that i need to post my link, big thumbnail and my custom description as shown in this image.
How to achieve this?
link to image - How my posts should look like
bigger images in facebook posts when posting
Use the Open Graph to create the custom stories.
Related
I'm using Facebook Ads API to create unpublished page posts. I have a problem when I try to publish those page posts which are videos with call-to-action button. I create unpublished page posts successfully and then I publish the unpublished posts from power editor, but it shows this message when I try to publish unpublished page posts I created:
Sorry, something went wrong. Please try again.
I tried to remove call_to_action from the code, posts get published without any problem. I'm using Marketing API integrated with my app and use user access token with those permissions:
manage_pages, publish_pages, ads_management, business_management, public_profile.
I need help to be able to publish unpublished posts (videos) with CTA button.
Here's the code I use:
$video_data = new AdCreativeVideoData();
$video_data->setData(array(
AdCreativeVideoDataFields::DESCRIPTION => '<DESCRIPTION>',
AdCreativeVideoDataFields::IMAGE_URL => '<IMAGE_URL>',
AdCreativeVideoDataFields::VIDEO_ID => '<VIDEO_ID>',
AdCreativeVideoDataFields::CALL_TO_ACTION => array(
'type' => AdCreativeCallToActionTypeValues::LEARN_MORE,
'value' => array(
'link' => '<URL>',
'link_title' => '<LINK TITLE>',
'link_caption' => '<LINK CAPTION>',
'link_format' => 'VIDEO_LPP',
),
),
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => '<PAGE_ID>',
AdCreativeObjectStorySpecFields::VIDEO_DATA => $video_data,
));
$creative = new AdCreative(null, 'act_<Ad_ACCOUNT_ID>');
$creative->setData(array(
AdCreativeFields::NAME => 'Sample Creative',
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
$creative->create();
Hope to get help, Thanks!
To publish unpublished post through API, you can make a POST call like /?is_published=true.
For the error from PowerEditor, it is lack of information for me to share any insights. It would be preferable to file a bug to Facebook for this type of issues. You are safe to share more details in the bug tool and Facebook can also pull information from their logs for troubleshooting.
In case you do not know the link to Facebook Bug Tool. https://developers.facebook.com/bugs/
So I'm creating posts to the facebook user's wall using Graph API
I'm referring to the 'caption' as stated here:
http://nocturnsoft.com/devblog/?p=906
when I specified the 'caption' option, the text in the caption would appear properly for profiles that uses the timeline, but for profile that use the old style, the caption would not appear...
Am I doing something wrong here or is this how it's supposed to be....If it is how it's supposed to be, how would I display text beneath the link for the Facebook post for non timeline profiles
btw: I'm using Facebook PHP SDK
In my apps the post data array looks like this and the caption (message) is present on both new and old profiles.
/* post to fb */
$post = array(
'access_token' => $fb_access_token,
'message' => 'THIS IS YOUR CAPTION HERE',
'link' => 'LINK TO YOUR SITE OR APP HERE',
'picture' => 'URL TO IMAGE HERE',
'name' => 'APP NAME HERE',
'description' => 'AWESOME DESCRIPTION ABOUT YOUR APP GOES RIGHT HERE!'
);
$res = $facebook->api('/me/feed', 'POST', $post);
Hope this helps. If so don't forget to say so! :)
i'm using this code to post to my application page as the page and not the admin:
$page_info = $facebook->api("/344722062246773?fields=access_token");
$attachment2 = array('message' => $row["nwmsg"],
'access_token' => $page_info['access_token'],
'name' => $row["nwnm"],
'caption' => $row["nwsubject"],
'picture' => 'http://itradegame.com/itrade/' . $row["nwposter"],
'description' => $row["nwtext"],
'actions' => array(array ('name'=> 'Play!','link'=> 'https://apps.facebook.com/itradee/')));
$result = $facebook->api('/344722062246773/feed/','post',$attachment2);
but the wierd thing is the users who likes the page can see the post on thier news feed but can't see it on the page itself.
why?
Because of the new timeline feature, posts by users (all except the page itself) will be listed under 'Recent Posts by Others on { PAGE_NAME}' section.
Please check the section.
I am adding functionality to post to a visitors Facebook wall.
I am using the following code:
$path_to_image = "http://projects.kleelof.com/boot_designer/image_interchange.php?c=" . $file_id;
$attachment = array('message' => 'this is my message',
'name' => 'The name of your company',
'caption' => "Caption of the Post",
'link' => $path_to_image,
'picture' => $path_to_image,
'description' => 'this is a description',
'access_token' => $facebook->getAccessToken()
);
//echo($path_to_image);
$result = $facebook->api('/me/feed/','post',$attachment);
The post appears on my wall, but not the image.
You can see the full process and post it makes by trying the app at: http://projects.kleelof.com/boot_designer - Then select either one of the 2 links.
take care,
lee
I think the path to the image needs to be and actual file system path, and the image will be read and uploaded along with the request for FB to process. Also, it needs to start with a # to actually upload it.
I am desperately looking for image attachment php api feeds for my facebook app.
Basically what I am trying to do is send an image attachment, along with an automatic "post to friends wall" action.
The idea behind it is that a user sends a "virtual burger" to their friends wall, with a message offering them a discount.
This is a snippet of the code that successfully sends the message, but I can't get the attachment to work.
if($_REQUEST['friend_1']!='' && $_REQUEST['friend_1']!="Start typing a friend's name") {
try {
$fql1 = "select name from user where uid=" . $_REQUEST['friend_1'];
$param1 = array(
'method' => 'fql.query',
'query' => $fql1,
'callback' => ''
);
$fqlResult1 = $facebook->api($param1);
$friend_1_name = $fqlResult1[0]['name'];
$statusUpdate = $facebook->api('/'.$_REQUEST['friend_1'].'/feed', 'post', array('link' => $fanpageURL, 'name' => 'Have a virtual Unity Burger.', 'description' => " ".$user_name." just sent you a virtual Unity Burger. If you would rather have the real thing then come add your name on the Unity list and we will give you a 20% discount on your next visit and an exclusive Unity keyring.", 'properties' => '', 'cb' => ''));
} catch (FacebookApiException $e) {
//echo "Notification not send to user ".$fqlResult1[0]['name']."<br>";
I think there are two ways to attach an image to a wall post.
The first one is to define the meta og:image in the target page and post the link to the friends wall. Facebook will query the target and grab the Open Graph info displaying it in the wall. You can test this with the Facebook Debugger.
The meta property should look like this:
<meta property="og:image" content="http://url.to/image" />
You can also define other Open Graph properties like title, description, etc.
The second way to attach the image to the post is to include the picture parameter in the Graph API call. In your code you only define some parameters (link, name, description...) but you can also send picture, caption, message...
So your API call could be like this:
$params = array( 'access_token' => '',
'message' => '',
'link' => '',
'picture' => '',
'name' => '',
'caption' => '',
'description' => ''
);
$wallPost = $facebook->api('/'.$to.'/feed', 'post', $params);