public function fbtest()
{
$db =& JFactory::getDBO();
$fb_user_id = 999999999;
$db->setQuery("SELECT access_token FROM jos_jfbconnect_user_map WHERE fb_user_id=$fb_user_id");
$access_token = $db->loadResult();
require_once(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_jfbconnect' . DS . 'assets' . DS . 'facebook-api' . DS . 'facebook.php');
$facebook = new JFBConnectFacebookLibrary();
$fbClient = $facebook->getFbClient();
$fbClient->setAccessToken($access_token);
$result = $facebook->api('/' . $fb_user_id . ''/?fields=accounts');
foreach ($result['accounts']['data'] as $page)
{
if (strtolower($page['id']) == '358473437989126')
{
$pageid = $page['id'];
$page_access_token = $page['access_token'];
}
}
$attachment = array(
'picture' => 'http://www.element67.com/templates/ih2012/img/logo400.png',
'link' => 'http://www.element67.com/somelink.html',
'message' => "This is the message that gets posted",
'caption' => 'This is the caption',
'description' => "This is the description of this post",
'actions' => array(array('name' => 'Enter a Contest!', 'link' => 'http://www.element67.com/contests/')),
'access_token' => $page_access_token
);
$result = $facebook->api('/me/feed', $attachment, true);
echo "" . print_r($result, true) . "";
}
Once granted, you don't need to ask this permission again. The access token you get from Facebook from that point forward should work with that permission, even if you remove it from the permission requests in JFBConnect. As long as you don't revoke that permission from within Facebook, it will continue to work for your app/site.But this is a hack, of course, and would have to be repeated if the user ever logged out from Facebook and a new access_token had to be generated on next login.
Yeah, publish to Page has been a feature we've been tossing around for (probably) a year or so now. The main reason we haven't implemented it is complexity and user-issues. The possibility for accidents is huge as someone may publish, and unpublish articles to test, create 'dummy' articles for whatever reason, and countless other scenarios. With auto-post, things can get out without the proper checks. We honestly know this because other extensions do the auto-publish thing, break, and then users have blamed us... we get an irate forum post about once a month about it.. seriously... and it *can't* have been JFBConnect...PS: You probably thought about this for 30 seconds and realized the big win here - you could use this to create a feature where a link to an article is posted to a fan page, as the page, when the article goes "published."
True, but from what you stated above, you'd only need this for an admin user and likely only for one Page... so, once done, you'd never need to do it again.So to get the permissions, the "hack" of adding them, logging in, and then removing them works - it's not pretty, of course. And in the unlikely event that a new user registers while this is being done, that might be odd, but it is what it is.
Join our newsletter to get alerts for Joomla releases, tips and tricks and extension updates.