开发者

Facebook Batch Post Requests using PHP

I'm trying to make a batch request using PHP that make a post in the user wall without any luck. I have succeed to make bath request of a type "GET" but not of a type "POST".

My code:

    $batched_request = '[{"method":"POST","relative_url":"me/feed","body": "message=hi"},' .
    '{"method":"GET","relative_url":"me/feed?limit=1"}]';

    $post_url = "https://graph.facebook.com/" . "?batch=" 
    .开发者_运维技巧 $batched_request
    . "&access_token=" . $access_token . "&method=post";
    echo $post_url;

    $post = file_get_contents($post_url);
    echo '<p>Response: <pre>' . $post . '</pre></p>';
    $decoded_response = json_decode($post, true);
    print_r($decoded_response);

If I change $batched_request to be only:

$batched_request = '[{"method":"GET","relative_url":"me/feed?limit=1"}]';

The batch request will suceeded and will show me the first post of the user wall.. but what is my problem with my POST request?


I wrapped the $batched_request within urlencode() and it worked like a charm:

$batched_request = '[{"method":"POST","relative_url":"me/feed","body": "message=hi"},' .
'{"method":"GET","relative_url":"me/feed?limit=1"}]';

$post_url = "https://graph.facebook.com/" . "?batch=" 
. urlencode($batched_request)
. "&access_token=" . $access_token . "&method=post";
echo $post_url;

$post = file_get_contents($post_url);
echo '<p>Response: <pre>' . $post . '</pre></p>';
$decoded_response = json_decode($post, true);
print_r($decoded_response);

Also make sure you have granted the publish_stream permission.

Facebook Batch Post Requests using PHP


This class will simplify making batch requests to Facebook.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜