Advanced access to Facebook API (Post to user wall, Post to pages, FQL, Insights)
Post to wall
To be able to post to users wall you need to add "publish_stream" to the requested scope
<?php $facebook = $hybridauth->authenticate( "Facebook" ); $facebook->api()->api("/me/feed", "post", array( "message" => "Hi there", "picture" => "http://www.mywebsite.com/path/to/an/image.jpg", "link" => "http://www.mywebsite.com/path/to/a/page/", "name" => "My page name", "caption" => "And caption" ));
Post to pages
To be able to manage users accounts you need to add "manage_pages" to the requested scope
<?php $facebook = $hybridauth->authenticate( "Facebook" ); // ask facebook api for the user accounts $accounts = $facebook->api()->api('/me/accounts'); // post "hello word!" to every pages for the current user foreach( $accounts['data'] as $account ){ $params = array( 'access_token' => $account['access_token'], 'message' => "hello word!" ); // ask facebook api to post the message to the selected account $facebook->api()->api( "/" . $account['id'] . "/feed", 'POST', $params ); }
Evaluates an FQL (Facebook Query Language) query
<?php
$facebook = $hybridauth->authenticate( "Facebook" );
$response = $facebook->api()->api(array(
'method' => 'fql.query',
'query' => "select name from profile where id=me()",
));
print_r( $response );
Array
(
[0] => Array
(
[name] => Hybrid Auth
)
)
Access Facebook Insights data
<?php $facebook = $hybridauth->authenticate( "Facebook" ); $response = $facebook->api()->api(array( 'method' => 'fql.query', 'query' => "select name from profile where id=me()", )); print_r( $response );
Array ( [0] => Array ( [name] => Hybrid Auth ) )
Access Facebook Insights data
To read insights you need to add "read_insights" to the requested scope
<?php $facebook = $hybridauth->authenticate( "Facebook" ); $response = $facebook->api()->api(array( 'method' => 'fql.query', 'query' => "SELECT metric, value FROM insights WHERE object_id=2439131959 AND metric='application_active_users' AND end_time=end_time_date('2011-06-26') AND period=period('month')", )); print_r( $response );
Array ( [0] => Array ( [metric] => application_active_users [value] => 955848 ) )