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
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.

Edited by Mahngiel
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.