Facebook Graph API: How to add vote links to a wall post? - php

I am building a Facebook app with voting included. With it I want to send a message to the user's wall including some text and two or more links.
I also want to control the link text so that I can get links like "Yes" and "No".
The first thing I tried was posting regular -tags, but (no surprise) that didn't work. I have seen other apps do this though. Are there any special tags that allow links?
Thank you.

I'll assume that you're using the Graph API and already have publish a post working.
I think the properties property might be what you are looking for (it is left out of the new API reference but is described here). This allows links although they might not be formatted quite how you want. Example:
$data = array (
'name' => ...,
'link' => ...,
'properties' => array (
'Yes' => array (
'text' => 'Vote',
'href' => 'http://www.example.com?vote=yes'
),
'No' => array (
'text' => 'Vote',
'href' => 'http://www.example.com?vote=no'
)
),
); //And whatever other properties you want
$facebook->api('/uid/feed', 'POST', $data);
The properties will appear after beneath description in the post and come out like the following:
Yes: Vote

Related

Exclude live events from YouTube data api search query

I'm using the google-api-php-client (https://github.com/google/google-api-php-client) to search and retrieve only videos from YouTube. I know you can set a query marker called type to video like this:
$searchquery = array(
'q' => "flux",
'maxResults' => 10,
'type' => 'video',
'videoDuration' => 'short',
'videoEmbeddable' => 'true'
);
However it seems to also return live events/livestreams in the search results. Is there a way to exclude live event videos? They have a marker called [liveBroadcastContent] => upcoming so I can do post-search but that's not ideal. Thanks in advance.
edit: on closer inspection, not all livestreams even seem to have the marker [liveBroadcastContent] set. I have found some that are set to none as with ordinary videos.

facebook PHP SDK posting as activity, not post

I hope you will be able to help me.
I'm developing an app, and I'm willing to post an activity (that appears on user timeline in recent activity) everytime the user use my application.
Although, for the moment, I have this code below, and it only posts a normal link :
if($can_post){
$facebook->api('/'.$uid.'/feed', 'post', array(
'message' => '',
'name' => 'Name',
'caption' => 'Caption',
'description' => 'SDesc',
'picture' => 'picture url',
'link' => 'link',
'actions' => array(array('name' => 'catch phrase',
'link' => 'http://link'))
));
Check out this guide on posting "stories" to the user's timeline using the Open Graph API, so maybe it's this functionality that you need. The example they give is just a like, but it can be easily modified.
Be aware that Facebook will have to approve you app again if you want to use stories (see end of page on link above).
It's also worth noting that Facebook have also defined a wide range of predefined "Actions" to help in the process, so it's a good idea to check to see if your app falls into one of these categories.

Is it possible to tag friends in video with graph api?

I haven't find anything related. Might be i would have searched wrongly.
I want to tag friends in video.
How do i do that using graph api in facebook?
It is possible to tag friends in a video, but it's just not in the documentation. I've searched quite some time myself to no avail, but then tried a couple of things and got it working.
The two permissions you need are publish_actions and user_videos.
It works quite similar to tagging photos, which is done with the /{photo_id}/tags endpoint. Although the video equivalent /{video_id}/tags is nowhere to be found in the documenation, it apparently does exist.
With photos you can supply the parameter tags as an array. Video tagging only supports one tag at a time with the tag_uid parameter. So if you want to tag multiple people, you'll have to do multiple posts.
This is the final working solution with the PHP SDK:
$facebook = new Facebook(array('[YOUR_APP_ID]', '[YOUR_APP_SECRET]'));
$response = $facebook->api('/me/videos', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'title' => '[YOUR_TITLE]',
'description' => '[YOUR_DESCRIPTION]',
'source' => '#' . realpath('[PATH_TO_YOUR_VIDEO')
));
$facebook->api('/' . $response['id'] . '/tags', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'tag_uid' => '[FRIENDS_FACEBOOK_ID]'
));
Read this
https://developers.facebook.com/docs/reference/api/post/
The post supports adding message tags.
Under the message_tags column
object containing fields whose names are the indexes to where objects are mentioned in the message field; each field in turn is an array containing an object with id, name, offset, and length fields, where length is the length, within the message field, of the object mentioned

Post to Timeline - with a date in the past

(noob question)
Using the example.php that comes with the PHP SDK I can post to my timeline successfully.
I'd like though to be able to set the date, so I added:
:
:
'created_time' => "2012-06-21T13:46:10+0000",
'updated_time' => "2012-02-19T14:46:10+0000",
'actions' => array(
array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
?>
<?php endif ?>
But created_time is ignored, the post is always "NOW". I've searched around for a solution to this but found nothing. Am i doing something wrong, is it a typo, or just not possible like this?
Looking on the web I did find articles about placing "ACTIONS" in the past - e.g.: How can I add a custom date to the facebook timeline through graph api
Is that the (only?) way to go, create a "publish" action ,,. with start_time etc.? Any links to how to do this (in PHP?)
You can only create actions in the past, not Posts using the API. However, you can manually change the date of a post using the Activity Log - it doesn't look like this feature is available via the API yet.

how to add share action to the post in facebook?

i'm using this code to post to my application wall
$attachment = array('message' => 'xxxxxxxxxxxxxxxx...',
'name' => 'xxxxxxxxxxxxxxxxxxx',
'caption' => 'xxxxxxxxxxxxxxxxxx',
'link' => 'xxxxxxxxxxxxxxxxxx',
'description' => 'xxxxxxxxxxxxxxxxxx',
'picture' => 'xxxxxxxxxxxxxxxxxx',
'actions' => array(array('name' => 'Download!',
'link' => 'xxxxxxxxxxxxxxxxxx'))
);
$result = $facebook->api('/2222222222222/feed/','post',$attachment);
when i post to my application wall manually the post is appearing on the application users wall with the share action
but when i use the above code it only appear on the app wall with like and comment actions only.
why?
and how to add the share action to the actions array?
i didn't find any answer online, but i just found the solution to my problem by chance
i removed the action parameter from the attachment.
but if there is a link parameter in the attachment the share action won't appear so you will have to give up the link parameter.
the proper names for the action link is:
array( array('text' => 'Download!', 'href' => 'xxxxxxxxxxxxxxx'));
Keep in mind that you can't use action links in the graph api (yet). so this functionality is limited to the REST api.
Let me know if this helps
http://facebookanswers.co.uk/?p=270
This article explains it. The key is this:
'actions' => array('name'=>'Sweet FA','link'=>'http://www.facebookanswers.co.uk'),
This is fine for adding one action. However, I'm not sure how to add two.
Hi the solution is here
instead of
$result = $facebook->api('/2222222222222/feed/','post',$attachment);
use
$result = $facebook->api('/2222222222222/links/','post',$attachment);
i'm still facing one little problem with the picture not showing after this change, if i come to a solution to it I'll come back here and post it.

Categories