0

首先谢谢你!感谢这个社区编辑 FB 应用程序也为我提供了一些可能。其次,对不起我的英语不好。

这是我的问题:我想在用户的墙上发布一条消息,但前提是他们想要。所以我设置了一个表单,用户可以选择是否在他们的墙上发布内容。问题是当用户发送表单时,我收到一条错误消息:OAuthException: (#200) 用户尚未授权应用程序执行此操作。所以我确定它与访问令牌有关,但我不明白出了什么问题。这是我的代码:

<?php
require_once "fb_app/facebook.php";
$facebook = new Facebook(array(
    'appId'  => '***',
    'secret' => '***',
    'cookie' => true
));
function grokSignedRequest() {
    if (isset($_REQUEST['signed_request'])) {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      return $data;
    }
    return false; }
$userID = $facebook->getUser(); 
$sr_dati = grokSignedRequest();
$firendsWall=$_POST['firendsWall'];
$likeStatus=$_POST['likeStatus'];
if ($sr_dati->page->liked==1 or $likeStatus==1) {
if ($userID) { // Checks if there is already a logged in user
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    // Will throw the very first time as the token is not valid
    error_log($e);
    $userID = null;
   }
}

if(empty($userID)) {  
    # There's no active session, let's generate one  
    $login_url = $facebook->getLoginUrl(array(  
        "response_type"=>"token", //Can also be "code" if you need to 
        "scope" => 'email,user_birthday,status_update,publish_stream,user_photos,user_videos,photo_upload,user_status' , 
        "redirect_uri"=> "http://www.facebook.com/pages/V....." //Your app callback url 
    ));  
    echo "<script type='text/javascript'>top.location.href = '" . $login_url. "';</script>";  
    exit;  
} 
//pubblico contenuto sulla bacheca di un utente
if ($firendsWall==1){
    try {$args = array(
    'message'   => 'Hello',
    'link'      => 'aaaa',
    'caption'   => 'vvvvvv!'
);
$post_id = $facebook->api("/".$userID."/feed", "post", $args);}
 catch (FacebookApiException $f) {
    // Will throw the very first time as the token is not valid
    echo $f;} }}
?>
4

0 回答 0