2012-05-08 25 views
1

創建Facebook應用程序Facebook 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); 

員額的作品,但它就像我的貼吧出現,而不是應用程序,建議?

+0

你是怎麼得到'$ token'的?什麼是'$ pId'? – grossvogel

+0

令牌我已經保存在一個分貝和pId是Facebook的人員ID – Lagoo87

+0

而且你保存的令牌是爲特定用戶,我想?我並不感到驚訝,這是代表用戶發佈給用戶的Feed,但我不知道如何(或者是否有可能)發佈爲應用。 – grossvogel

回答

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

可能是它可以幫助你的代碼。

+0

對不起,我是個白癡。我確定你的代碼有效,我的工作也很好 - 我只是忘記了我在Facebook下創建了應用程序,而不是應用程序的Facebook,這就是爲什麼它發佈爲我。對不起,很蠢!我想我應該睡更多哈哈 – Lagoo87