I'm trying to make a Facebook video application so users can have a video stored on my site displayed on their wall using Facebook Open Graph.
I'm using the below code for user login.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'MYAPPID', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
Now how do I implement the Watch action?
curl -F 'access_token=myaccesstoken' \
-F 'movie=http://samples.ogp.me/453907197960619' \
'https://graph.facebook.com/me/video.watches'
And this
curl 'https://graph.facebook.com/me/video.watches?access_token=myaccesstoken'
in PHP? And how can I get the access token of users?
To get the user access token in PHP SDK 3.1.1:
// Get the current access token
$access_token = $facebook->getAccessToken();
Refer to: https://developers.facebook.com/docs/reference/php/facebook-getAccessToken/
Posting Actions.
Refer to: https://developers.facebook.com/docs/opengraph/tutorial/
This tutorial will guide you through the key steps to build, test, and publish your first Open Graph application. We will build a sample recipe application that allows users to publish stories about cooking recipes. Before starting, please review the Open Graph Checklist which will not only help in your app design and planning, but will also help speed up the application review process.
Step 1: Create a Facebook applications. https://developers.facebook.com/docs/opengraph/tutorial/#create-app
Step 2: Authenticate users with the Login Button plugin. https://developers.facebook.com/docs/opengraph/tutorial/#authenticate
Step 3: Define Objects, Actions and Aggregations through the App Dashboard. https://developers.facebook.com/docs/opengraph/tutorial/#define
Step 4: Publish Actions for your users. https://developers.facebook.com/docs/opengraph/tutorial/#publish
Step 5: Add Social Plugins to your application. https://developers.facebook.com/docs/opengraph/tutorial/#plugins
Step 6: Submit Your Actions for approval. https://developers.facebook.com/docs/opengraph/tutorial/#submit
EXAMPLE:
if ($user){
$queries = array(
// The URL build is me/ namespace : action ? object = URL
array('method' => 'POST', 'relative_url' => '/me/anotherfeed:view?feed=http://anotherfeed.com/')
// Any other API calls needed, this is a batch request for performance.
);
try {
$postResponseA = $facebook->api('?batch='.json_encode($queries), 'POST');
}
catch (FacebookApiException $e) {
//echo 'AF error: '.$e.'';
}
// Returns the id of posted actions if true.
$actions = json_decode($postResponseA[0][body], true);