English 中文(简体)
how to use curl to post message to a facebook business page?
原标题:
  • 时间:2009-11-13 03:56:21
  •  标签:
  • php
  • curl

I wonder there is a way to post a message to a facebook business page with cURL?

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.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签