【发布时间】:2010-06-21 12:59:28
【问题描述】:
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
文档说我需要发布一个才能发布到墙上。
【问题讨论】:
curl -F 'access_token=...' \
-F 'message=Hello, Arjun. I like this new API.' \
https://graph.facebook.com/arjun/feed
文档说我需要发布一个才能发布到墙上。
【问题讨论】:
值得一提的是,MANCHUCK 建议使用 cURL 并不是实现此功能的最佳方式,因为 cURL 不是 PHP 的核心扩展。管理员必须手动编译/启用它,它可能并非在所有主机上都可用。正如我在博客中已经指出的那样 - PHP has native support for POSTing data 从 PHP 4.3 版本开始(8 年前发布!)。
// Your POST data
$data = http_build_query(array(
'param1' => 'data1',
'param2' => 'data2'
));
// Create HTTP stream context
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $data
)
));
// Make POST request
$response = file_get_contents('http://example.com', false, $context);
【讨论】:
在 php 中使用 curl* 系列函数。
一个例子:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/arjun/feed');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('access_token' => 'my token',
'message' => 'Hello, Arjun. I like this new API.'));
curl_exec($ch);
【讨论】: