Jump to content

Codeigniter And Facebook Sdk


ShoeLace1291

Recommended Posts

I am trying to give my users the ability to share one of my articles on their facebook page, but I am having a few problems. I don't believe that the problem lies within my app, because it works perfectly in the example... there's just something wrong with my code. The getLoginUrl variable as an anchor just takes me back to the same exact page within my site, but it still tells me i'm not logged in. It never redirects me. This is the code I have so far:

 

function facebook($article_id){

    $config = array(
	    'appId' => '276870792431073',
	    'secret' => '8d49eee575413fb9a8063d22f65dbf6a'
    );

    $this->load->library('facebook', $config);

    $user = $this->facebook->getUser();

    if ($user) {
	    try {
		  // Proceed knowing you have a logged in user who's authenticated.
		  $user_profile = $this->facebook->api('/me');
	    } catch (FacebookApiException $e) {
		  error_log($e);
		  $user = null;
	    }
	  }

    if($user){

	    $article = $this->article->fetch_article($article_id);
	    $config = array(
		    'message' => 'I just read an '.anchor('articles/'.url_title($article['title']).'/'.$article_id, 'article').' on '.anchor('', 'TrackTheOutbreak.com').'!',

	    );

	    $this->facebook->api('/me/feed', 'post', $config);

    } else {

	    $data['MESSAGE_TITLE'] = 'Authentication Error';
	    $data['MESSAGE_TEXT'] = 'You must be logged into an existing Facebook account to use this feature.  Click '.anchor($this->facebook->getLoginUrl(), 'here').' to login.';
	    $this->parser->parse('error_body.tpl', $data);

    }
   }

Link to comment
https://forums.phpfreaks.com/topic/269052-codeigniter-and-facebook-sdk/
Share on other sites

you have this: $user = $this->facebook->getUser(); , but you're not passing anything to the library to return with. How is that being populated? You're going to have to paste that library code.

 

Oh, and you're going to want to change your API ID & secret, as it's likely already been cached by the search bots.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.