Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when requesting Facebook PHP Api?

Tags:

php

facebook

I normally use only the facebook javascript api, but the login started to give me trouble so I'm trying with the PHP api. This is the api call in my header:

<?
require 'stuff/facebook-php/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'my app id',
  'secret' => 'secret',
));

// Get User ID
$user = $facebook->getUser();
?>

I get these messages on my site:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/02/6945202/html/copoetry/index.php:6) in /home/content/02/6945202/html/copoetry/stuff/facebook-php/src/facebook.php on line 37

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/02/6945202/html/copoetry/index.php:6) in /home/content/02/6945202/html/copoetry/stuff/facebook-php/src/facebook.php on line 37

Am I doing something wrong or what could be the issue? Thanks

like image 569
lisovaccaro Avatar asked Aug 01 '11 01:08

lisovaccaro


People also ask

Why is Facebook giving me an error message?

If you see an error message saying “You can't reply to this conversation,” it might be because: A message or something you shared goes against our Community Standards. You recently sent an unusual number of messages, which may seem like spam to our security system. Messages you sent were marked as unwelcome.

What is an OAuthException error?

OAuthException: If you receive an OAuthException error, it means that Edgar doesn't have the correct permissions to access your Facebook accounts right now. The password may have been changed on Facebook or Facebook may have reset your security session.


2 Answers

"Cannot send session cookie - headers already sent error"

means you've outputted some data on the page and then tried to set headers. Headers must be sent before any html output.

ALSO

"Cannot send session cookie - headers already sent" comes often when the file is encoded in UTF-8 WITH BOM under Windows. When transfered on an UNIX server the BOM is considered as text and sent before any header you can define.

Make sure to remove any spaces, newlines, or other garbage before an opening <?php tag or after a closing ?>

like image 171
ThatGuy Avatar answered Oct 23 '22 23:10

ThatGuy


Make sure you didn't output any string (including errors) before starting your session.

Do not use ?> if you are sure your last line of your file is php code

<?php
require 'stuff/facebook-php/src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'my app id',
  'secret' => 'secret',
));

// Get User ID
$user = $facebook->getUser();
like image 2
genesis Avatar answered Oct 23 '22 23:10

genesis