0

I'm very confused with this facebook api.

I've facebook username and password in my database, I want to sign and post content from my site to my facebook wall. how do I do it?

I've downloaded the facebook-php-sdk, just need to be able to include the "post" part in my php file to make things happen, I've this code at the moment

require_once ('facebook.php');
                $app_id = "MY_ID";
                $app_secret = "MY_SECRET";
                $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));

                if(is_null($facebook->getUser())) {

                    header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                    exit;
                } 

                $status = $facebook->api('/me/feed', 'POST', array('message' => utf8_encode($my_message)));

with this I just get a internal server error, nothing more to have an idea of what I'm doing wrong...

even with var_dump($status) I get nothing Thanks

Pluda
  • 1,479
  • 6
  • 21
  • 45
  • Check your php error logs. You likely are receiving an error. – John Cartwright Jun 01 '11 at 14:35
  • if that's a copy and paste without editing to your needs, those variables ($my_message) would contain nothing. And hopefully you have replaced MY_ID with "your ID" and My_SECRET with your "secret key" generated by facebook? – robx Jun 01 '11 at 14:35
  • I did change my ID and my SECRET :-) – Pluda Jun 01 '11 at 14:54

2 Answers2

1

You cannot log in as a user on the Facebook Graph API. You should never be asking for any user's Facebook password in the first place, which is why Facebook do not allow this.

The API allows you to log in as an 'app', which can be granted permissions by Facebook users. You will need to create a Facebook app at https://www.facebook.com/developers/apps.php.

Once this is done, you can prompt a user to post on their wall or use the Graph API using http://developers.facebook.com/docs/reference/dialogs/feed/

Connell
  • 13,925
  • 11
  • 59
  • 92
  • "you can prompt a user to post on the wall" Hello, on the wall of my aplication? No, I wanted to post on user wall, based on is email/password, this is a kind of blog, if user also wants to publish to facebook, he checks a checkbox and the php does the rest, that is my intention – Pluda Jun 01 '11 at 15:07
  • Yes, It posts to the user wall. Please read the very first line of the second link I sent. Also if you scroll down on that link you will find how to do this with the Graph API. – Connell Jun 01 '11 at 15:10
  • not exactly what I want... I'm not asking for passwords, user enters is password, I just have mine on my database :-) – Pluda Jun 01 '11 at 15:30
  • What do you want then? That code can post to a user's own wall. How do you mean you're not asking for passwords, but the user enters it? – Connell Jun 01 '11 at 15:34
  • like a blog, you go to admin page on your blog account and when you click on the button to publish, I ask you "want to publish on facebook also? if yes, you have a username and password fields, you put there your info and its done, you have your blog and your facebook with a new publication – Pluda Jun 01 '11 at 15:43
  • You shouldn't be asking for other users' Facebook passwords if you're handling the post server side. The users don't know if you're going to save that information or not, but if it were me and a website asked for mine, I certainly wouldn't do it. Facebook also frown upon this and make it clear that you're not allowed to at any point give out your Facebook password to any 3rd party websites. You should have an app for your blog, let users authenticate this app, then post on their walls using the Graph API. – Connell Jun 01 '11 at 15:49
  • Facebook do this for security reasons. Each app has to request special permissions to access certain profile information, but with your password they can do anything you want. You can also reject or block an app at any time using Facebook's privacy settings. Also, on the plus side, this would mean if a user changes their password, you still have access to their wall. – Connell Jun 01 '11 at 15:51
  • I'm not storing anything, but you're write, I can store if I want. I did everything, I've that facebook app and so on, but can't make it work. I need to study this, it's not so easy has we can read in some posts or forums. – Pluda Jun 01 '11 at 16:56
  • What problems are you having? – Connell Jun 02 '11 at 10:23
  • Hello! well, finally I manage this with help from this website http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/ – Pluda Jun 04 '11 at 17:02
  • it is not php, but its working fine, now my only problem is that my facebook posts are with html tags, like
    teste único 4?
    . I'm copying the innerHTML from a iframe into one textarea and posting the textarea.val()
    – Pluda Jun 04 '11 at 17:05
  • 1
    Then use javascript to get rid of your HTML tags. – Connell Jun 06 '11 at 11:47
0

Firstly try (i hope you entered your $app_id and $app_secret):

require_once ('facebook.php');
$app_id = "MY_ID";
$app_secret = "MY_SECRET";
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$user = $facebook->getUser();

var_export($user);

You should se data if you're logged in properly.

Than you should maybe look at this page for an example Facebook Graph API PHP SDK posting on page as page

Community
  • 1
  • 1
Anze Jarni
  • 1,141
  • 7
  • 7
  • ok, now I got 0 as result, nothing more. Maybe a stupid question, I've the app_id and the secret_key, those are from the app I'de to create in facebook. Now, I want to post to my wall, so, where do I put my username (my_email@me.com) and password? I mean, If I've 3 facebook acounts, I just need to change these email - password values and not the app_id and secret. I'm really confused – Pluda Jun 01 '11 at 14:57
  • You can obtain the app access token from the Graph API token endpoint at https://graph.facebook.com/oauth/access_token by specifying your app id, app secret and client_credentials in the grant_type parameter. Both the app id and app secret are generated when your app is created in the Developer App. Read more here:http://developers.facebook.com/docs/authentication/ – Anze Jarni Jun 01 '11 at 15:57