Created
February 18, 2012 01:46
-
-
Save empirefx/1856811 to your computer and use it in GitHub Desktop.
fb_connect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//...code... | |
// USE: Post wall in facebook page | |
//controller fb_connect.php | |
public function __construct() | |
{ | |
$CI = & get_instance(); | |
$CI->config->load("facebook",TRUE); | |
$config = $CI->config->item('facebook'); | |
parent::__construct($config); | |
$this->user_id = $this->getUser(); // New code | |
$me = null; | |
if ($this->user_id) { | |
try { | |
$me = $this->api('/me'); | |
$this->user = $me; | |
$page_id = 'YOUR_ID_FB_PAGE'; | |
$page_info = $this->api("/$page_id?fields=access_token"); | |
if( !empty($page_info['access_token']) ) { | |
$args = array( | |
'access_token' => $page_info['access_token'], | |
'message' => "I'm a Page!" | |
); | |
$post_id = $this->api("/$page_id/feed","post",$args); | |
} | |
} catch (FacebookApiException $e) { | |
error_log($e); | |
} | |
} | |
// login or logout url will be needed depending on current user state. | |
//(if using the javascript api as well, you may not need these.) | |
if ($me) { | |
$this->fbLogoutURL = $this->getLogoutUrl(); | |
} else { | |
$this->fbLoginURL = $this->getLoginUrl(); | |
} | |
} //end Fb_connect() function | |
//...code... | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//...code... | |
// USE: Post wall in facebook profile | |
//controller fb_connect.php | |
public function __construct() | |
{ | |
$CI = & get_instance(); | |
$CI->config->load("facebook",TRUE); | |
$config = $CI->config->item('facebook'); | |
parent::__construct($config); | |
$this->user_id = $this->getUser(); // New code | |
$me = null; | |
if ($this->user_id) { | |
try { | |
/** POST wall */ | |
$wall_post = array('message' => 'this is my message', | |
'name' => 'This is my demo Facebook application!', | |
'caption' => "Caption of the Post", | |
'link' => 'http://mylink.com', | |
'description' => 'this is a description' | |
); | |
$result = $this->api('/me/feed/', 'post', $wall_post); | |
/** POST wall */ | |
$me = $this->api('/me'); | |
$this->user = $me; | |
} catch (FacebookApiException $e) { | |
error_log($e); | |
} | |
} | |
// login or logout url will be needed depending on current user state. | |
//(if using the javascript api as well, you may not need these.) | |
if ($me) { | |
$this->fbLogoutURL = $this->getLogoutUrl(); | |
} else { | |
$this->fbLoginURL = $this->getLoginUrl(); | |
} | |
} //end Fb_connect() function | |
//...code... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment