这里是代码,这个代码工作得非常好,当帖子没有包含“链接字段”上的链接时,一条消息可以发送带或不带链接的“字段消息”中的链接在字段中发布消息吧看起来像一个可点击的文本链接 (http://www.mylinkposted.com/withoutmetadata/)您可以发送如下帖子:
嗨,我终于完成了我的新网站
根据您的经验,我会等待一些反馈。
但是如果在“链接字段”中写入(复制)链接,它将从中提取元数据,帖子将包括描述,标题,标题,图像,来源...... 如果用户在其他用户feed / wall上共享了一个链接,其中包含所有帖子参数,并且看起来很好,但通知它不会进入通知流,并且看起来真的垃圾邮件只是发布而不是发送通知,您认为可以解决这个问题?
$app_id = "xxxxxxxxxxxxxxxx"; $app_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; $site_url = "http://www.xxxxxxxxxxxxxxx.com/app00/index.php"; try{ include_once "src/facebook.php"; }catch(Exception $e){ error_log($e); } $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, )); $user = $facebook->getUser(); if($user){ try{ $user_profile = $facebook->api('/me'); }catch(FacebookApiException $e){ error_log($e); $user = NULL; } } if($user){ // Get logout URL $logoutUrl = $facebook->getLogoutUrl(); }else{ // Get login URL $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'publish_stream user_groups', 'redirect_uri' => $site_url, )); } if($user){ $queries = array( array('method' => 'GET', 'relative_url' => '/'.$user), array('method' => 'GET', 'relative_url' => '/'.$user.'/friends'), array('method' => 'GET', 'relative_url' => '/'.$user.'/groups'), array('method' => 'GET', 'relative_url' => '/'.$user.'/likes'), ); try{ $batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST'); }catch(Exception $o){ error_log($o); } //string. Decode for use as a PHP array. $user_info = json_decode($batchResponse[0]['body'], TRUE); $friends_list = json_decode($batchResponse[1]['body'], TRUE); $groups = json_decode($batchResponse[2]['body'], TRUE); $pages = json_decode($batchResponse[3]['body'], TRUE); if(isset($_POST['submit_x'])){ if($_POST['message'] || $_POST['link'] || $_POST['picture']) { $body = array( 'message' => $_POST['message'], 'link' => $_POST['link'], ); $batchPost=array(); $i=1; $flag=1; foreach($_POST as $key => $value) { if(strpos($key,"id_") === 0) { $batchPost[] = array('method' => 'POST', 'relative_url' => "/$value/feed", 'body' => http_build_query($body)); if($i++ == 50) { try{ $multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST'); }catch(FacebookApiException $e){ error_log($e); echo("Batch Post Failed"); } $flag=0; unset($batchPost); $i=1; } } } if(isset($batchPost)) { try{ $multiPostResponse = $facebook->api('?batch='.urlencode(json_encode($batchPost)), 'POST'); }catch(FacebookApiException $e){ error_log($e); echo("Batch Post Failed"); } $flag=0; } } else { $flag=2; } } }