facebook发布流

时间:2011-07-24 16:58:40

标签: php facebook api sdk stream

我有问题...我确实关注this site ...我不擅长facebook API ..抱歉我真的没有API ..

我的代码:

<?php


define('FB_APIKEY', '***************************');
define('FB_SECRET', '***************************');
define('FB_SESSION', '***************************');

require_once 'facebook-platform/php/facebook.php';

echo "post on wall";
echo "<br/>";

try {
 $facebook = new Facebook(FB_APIKEY, FB_SECRET);
 $facebook->api_client->session_key = FB_SESSION;
 $facebook->api_client->expires = 0;
 $message = 'testasdfsadf';

 $attachment = array(
 'name' => $_POST["name"],
 'href' => $_POST["href"],
 'description' => $_POST["description"],
 'media' => array(array('type' => 'image',
 'src' => $_POST["src"],
 'href' => $_POST["href"])));

 $action_links = array( array('text' => 'TITLE', 'href' => 'http://www.mysite.com'));

 $attachment = json_encode($attachment);
 $action_links = json_encode($action_links);

 $target_id = "2410160********";
 $session_key = FB_SESSION;


     if( $facebook->api_client->stream_publish($message, $attachment, $action_links, null, $target_id)) {
     echo "Added on FB Wall";
     }
     } catch(Exception $e) {
     echo $e . "<br />";
     }
?>

我收到了错误:

post on wall
exception 'FacebookRestClientException' with message 'The user hasn't authorized the application to perform this action' in /Users/*****/Sites/FacebookTEST/facebook-platform/php/facebookapi_php5_restlib.php:3025 Stack trace: #0 /Users/******/Sites/FacebookTEST/facebook-platform/php/facebookapi_php5_restlib.php(916): FacebookRestClient->call_method('facebook.stream...', Array) #1 /Users/******/Sites/FacebookTEST/index.php(46): FacebookRestClient->stream_publish('testasdfsadf', '{"name":null,"h...', '[{"text":"TITLE...', NULL, '2410160********') #2 {main}

1 个答案:

答案 0 :(得分:0)

我找到了答案:

此处解决方案: http://www.facebook.com/connect/prompt_permissions.php?api_key= YOUR_API_KEY &安培; V = 1.0&安培;下一个HTTP =?//www.facebook.com/connect/login_success.html xxRESULTTOKENxx&安培;显示=页面&安培; ext_perm = publish_stream,offline_access&安培; enable_profile_selector = 1&安培; profile_selector_ids = <强> ID_OF_YOUR_PAGE

在BOLD文本中插入API密钥和网页ID ..