2012-05-21 49 views
0

我的問題很簡單。如何張貼在最近的股票和活動,但不是在牆上(時間軸)與PHP。 (發佈操作)。 我在JavaScript中已經做了,但我想它在PHP帖子上的股票和活動最近,但不是在牆上用php

我已經測試這一點:

$params = array(
      'message'  => "This post is a test", 
      'name'   => "Titre de mon test", 
      'caption'  => "My Caption", 
      'description' => "Some Description...", 
      'link'   => "http://stackoverflow.com", 
      'actions' => array('name'=>'Recipe','link'=>'url'), 
      'picture'  => "http://i.imgur.com/VUBz8.png", 
     ); 

     $post = $facebook->api("/$user/feed","POST",$params); 

感謝。

我發現編輯:

我發現

<meta property="og:title" content="My article" /> 
<meta property="og:type" content="namespace:recipe" /> 
<meta property="og:url" content="http://url/" /> 
<meta property="og:image" content="" /> 
<meta property="fb:app_id" content="apikey" /> 
<meta property="og:description" content="My wonderful article" /> 

和PHP

try { 
     $action = array('name' => 'recipe', 'link' => 'http://url/'); 
     $actions = json_encode($action); 
     $params = array('recipe'=>'http://url/','access_token'=>$facebook->getAccessToken(), 'actions'=> urlencode($actions)); 
     $out = $facebook->api('/me/namespace:cook','post',$params); 
     echo "Your post was successfully posted to UID: $user"; 

    } 
    catch (FacebookApiException $e) { 
     $result = $e->getResult(); 
    } 


} 
+0

你是怎麼設法用javascript做到的? –

+0

FB.api( '/ me/namespace:cook', 'post', {recipe:'http:// url'}, 函數(響應){ if(!response || response.error) ('Cook was successful!Action ID:'+ response.id); } });其他{ }其他{ } –

回答

1

爲了發佈活動,你需要創建一個動作和對象。您需要按照http://developers.facebook.com/docs/opengraph/keyconcepts/的說明操作。

如果您已請求用戶的publish_actions權限,則您在問題中指定的PHP和JavaScript代碼是正確的,可將操作發佈到用戶的配置文件。在用戶使用之前,該行爲也需要得到Facebook的批准。

$params = array('recipe'=>'http://url/'); 
$out = $facebook->api('/me/namespace:cook','post', $params); 
if ($out) 
    echo "Activity posted"; 
else 
    echo "Post was unsuccessful"; 
相關問題