1

创建脸书应用

使用 cURL 从应用程序发布消息,但它似乎是我发布的?我怎样才能从应用程序发布,这是我的 cURL

    $attachment =  array(
    'access_token' => $token,
    'message' => '$message',
    'name' => '$name',
    'link' => '$link',
    'description' => '$description',
    'picture'=> '$picture',
    'actions' => json_encode(array('name' => '$name2','link' => '$link2'))
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$pId.'/feed');
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);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
$result = curl_exec($ch);
curl_close ($ch);

该帖子有效,但看起来好像我发布了它而不是应用程序,建议?!

4

1 回答 1

2

这是对我有用的代码

$file = 'image.jpg';
$args = array(
   'message' => 'Photo from application',
    'access_token'=>urlencode('Your Access token'),
);
$args[basename($file)] = '@'.realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$result = curl_exec($ch);
curl_close ($ch);

可能对你有帮助。

于 2012-05-09T10:40:31.490 回答