开发者

how to use curl to post message to a facebook business page?

I wonder there is a way to post a message to a facebook business page with c开发者_StackOverflowURL?

thanks


here is roughly what you need without entirely doing it for you:

<?php
$poststring = "email=" . $email . "&pass=" . $password;
$ch = curl_init('http://www.facebook.com/pages/create.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "$poststring");
curl_exec ($ch);
curl_close ($ch);

You want to build on the &poststring variable. This is what will actually contain the information you are going to send. For each field in the form, you must put that field name in the string, and then populate it with the data you want.

A good way to find all those easily is to open up the page in firefox with the Web Developer Toolbar and it will show you every field that's used in the form, and what name it is.

Beware, to prevent spam there are lot of tokens and authentication stuff put in hidden fields to prevent abuse (which hopefully isn't what you're doing) and you will have to figure out how to generate or obtain that information.


After you have authenticated the user and gotten a publish_right token run the script below

$url = "https://graph.facebook.com/user_id/feed";
$ch = curl_init();
$attachment =  array(   'access_token'  => access_token_here,                        
                    'name'          => "Rave Kenya",
                    'link'          => "www.youtube.com",
                    'description'   => 'Testing a new facebook app',
                    'message' => 'Tested',

                );

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result =curl_exec($ch);

curl_close ($ch);


Although just using curl sounds simpler, the most reliable and forward-compatible option is likely implementing Facebook's API. Using the API you can call Stream.publish with your Page's ID as the target ID.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜