2013-01-09 1 views
0

에 사진을 업로드 할 수 없습니다이 내 cron.phpOAuthException (# 240)이 사용자가이 오브젝트의 벽

나는 UID와 MySQL의 DB에서 액세스 토큰을 얻을
<?php 
ob_start(); 

// Load the required files 

require_once('fb_src/facebook.php'); 
require_once('includes/fb.php'); 
require_once('includes/db.php'); 
require('includes/timezone.php'); 


// Connect to the DB 

$con = mysql_connect(SERVER,USERNAME,PASSWORD); 
if (!$con) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db(DB, $con); 

$result = mysql_query("SELECT * FROM queue WHERE date_to_post='" . date("o-m-d") . "'"); 

// Fetch in the DB the content that is supposed to be posted today and echo it out 

date_default_timezone_set('CST'); 
echo "Date: " . date("o-m-d"); 
echo "<br/>Time: " . date(g) . ":" . date(i) . " " . date(A); 

// Connect to FB 

$facebook = new Facebook(array(
    'appId' => APPID, 
    'secret' => SECRET, 
    'cookie' => true, 
    'fileUpload' => true 
)); 

while($row = mysql_fetch_array($result)) 
{ 
    echo "ID: " . $row['id']; 
} 

echo "<br/><hr/><br/>"; 




echo "Connected...<br/>"; 



// Post the content in FB 

echo "<br/><br/>Query: SELECT * FROM queue WHERE date_to_post='" . date("o-m-d") . "'"; 
$result2 = mysql_query("SELECT * FROM queue WHERE date_to_post='" . date("o-m-d") . "'"); 


while($row = mysql_fetch_array($result2)) 
{ 
    $picture_path_query = mysql_query("SELECT * FROM messages WHERE id='" . $row['message_id'] . "'"); 
    while ($row_for_picture_path = mysql_fetch_array($picture_path_query)) { 
     $picture_path = "@" . realpath($row_for_picture_path['picture']); 
    } 
    echo "<br/>Picture Path: $picture_path <br/>"; 
    echo "<br/>Message ID: " . $row['message_id']; 
    /* if ((substr(strstr($row['time_to_post'], ':'), 0, 2) == ":" . substr(date('i'), 0, 1)) && (date(g) == substr($row['time_to_post'], 0, 1)) && (date(A) == $row['am_or_pm'])) { */ 
     try { 
      echo "<br/><br/>About to post...<br/><br/>"; 
      $uid = $row['uid']; 
      $message = $row['message_to_post']; 
      $picture = $picture_path; 
      echo "PIC: $picture <br/><br/>"; 
      $access_token = $row['access_token']; 
      $response = $facebook->api(
       "/$uid/photos/", 
       'post', 
       array(
       'access_token ' => $access_token, 
       'message' => $message, 
       'source' => $picture, 
       // @-sign must be the first character 
) 
      ); 
      echo "Reponse: $response"; 

      //} 
      echo "Posted message #" . $row['id'] . " with message '" . $row['message_to_post'] . "' and picture path '" . $row['picture'] . "' by user: '" . $uid . "'"; 
      } 

     catch(FacebookApiException $e) { 
      $login_url = $facebook->getLoginUrl(array(
       'scope' => 'publish_stream' 
      )); 

      print_r($e->getType()); 
      print_r($e->getMessage()); 
     } 
    } 
//} 

echo "<br/><br/><strong>Done.</strong> - <a href='" . $facebook->getLogoutUrl() . "'>Logout</a>"; 
ob_flush(); 
?> 

입니다. 해당 사용자가 내 앱을 대신하여 게시하고 뉴스 피드에 액세스하도록 허용했습니다. 나는이 스크립트를 실행하면 내가 얻을 :이 사용자는이 객체의 벽은 사용자의 벽이이 사진을 게시하려는 것 같습니다

답변

2

에 사진을 업로드 할 수 없습니다

OAuthException (# 240). /$uid/photos 대신 /me/photos을 사용하면 API relative_url이 오류가 발생하기 쉽습니다. 소유자가 access_token 인 경우 me을 지정합니다.

다른 생각 : 당신이 실제로 유효 예상 사용자에 속하고 올바른 사용 권한이 있는지 확인하기 위해 Facbook Debugger하여 데이터베이스에 저장 access_token을 확인 했습니까? 또한 저장된 uid이 올바른지 확인 했습니까?

+0

$ uid가 비어 있거나 null 인 내 첫번째 생각이었습니다 – Igy

+0

$ uid가 나에게 변경되었으며 사용자의 벽에 사진을 게시하지 않습니다. 이번에는 오류를 반환하지 않습니다. access_token의 유효성을 검사하고 올바른 사용자에게 속하는지 확인했습니다. 올바른 사용 권한도 있습니다. –

+0

로그인 한 페이스 북 계정이있는 브라우저 세션이 있으면 성공적으로 게시합니다. 페이스 북에 로그인 할 필요없이이 스크립트를 cron 작업으로 실행하려고합니다. –