Help encoding a cURL argument (works fine from the command line, but not from a PHP script) -
i working facebook api, , use following command via terminal post message users wall.
curl -f 'access_token=xxxxxxxxxx' \ -f 'message=hello world' \ -f 'to={["id":xxxxxxx]}' \ https://graph.facebook.com/me/feed
this works great. trying same via php code;
$fields = array( 'access_token' => $t, 'message' => $message, 'to' => '{["id":'.$id.']}' ); $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $fields); curl_exec($ch); curl_close($ch);
this code successfuly posts message, own wall (i.e. ignoring 'to' parameter). i'm new curl, , i'm sure encoding wrong, or maybe missing curl flag, i've been through several tutorials on posting via curl, including few answers, , can't see i'm missing.
really appreciate help!
what print out?
if ( 'post' == $_server[ 'request_method' ]) { echo 'posted: '; print_r( $_post ); exit; } $t = '121'; $message = 'helo worlds'; $id = 1234; $fields = array( 'access_token' => $t, 'message' => $message, 'to' => '{["id":'.$id.']}' ); $ch = curl_init(); curl_setopt($ch, curlopt_url, 'http://localhost:8888/testbed/' ); // script curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $fields); curl_setopt($ch, curlopt_returntransfer, true ); $out = curl_exec($ch); curl_close($ch); echo 'received[ ' . $out . ' ]';
prints on local box:
received[ posted: array ( [access_token] => 121 [message] => helo worlds [to] => {[\"id\":1234]} ) ]
Comments
Post a Comment