在PHP中帮助CURL

时间:2011-06-20 14:28:11

标签: php curl

我正在尝试用PHP编写代码:

curl -F 'access_token=123' \
 -F 'message=Hello, Arjun. I like this new API.' \
 https://graph.facebook.com/arjun/feed

但我不知道怎么做......

有什么想法吗?

由于

TheBounder。

1 个答案:

答案 0 :(得分:2)

你不能像这样执行curl,你必须先安装PHP扩展(cUrl)(在这里查看documentation)。

然后你可以这样做:

$url="https://graph.facebook.com/arjun/feed";
$ch = curl_init();
$vars = "message=YourMessage";
if($ch === FALSE){
   echo "Errore init curl";
}else{
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
    $returned = curl_exec($ch);
    $returned = html_entity_decode($returned);
    curl_close ($ch);

我刚刚复制了一些我以前用过的代码,把它当作一个起点。