Facebook cURL posting as me?

笑着哭i 提交于 2020-01-11 11:27:08

问题


Create facebook app

Using a cURL to post a message from an App but it's appearing to be posted from me? How can I can it to post from the app, here's my 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);

The post works, but it just appears as if I posted it and not the App, suggestions?!


回答1:


Here is the code it works for me

$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);

May be it helps you.



来源:https://stackoverflow.com/questions/10506060/facebook-curl-posting-as-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!