OAuthException(#240) 该用户不允许将照片上传到该对象的墙上

问题描述 投票:0回答:1

这是我的 cron.php

<?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();
?>

我从 mysql 数据库获取 UID 和访问令牌。该用户允许我的应用程序代表他们发布内容并访问新闻源。运行脚本后,我得到:

OAuthException(#240) 该用户不允许将照片上传到该对象的墙上

php facebook access-token photo facebook-oauth
1个回答
2
投票

您似乎正在尝试将这张照片发布到用户的墙上。如果您使用

/me/photos
而不是
/$uid/photos
,您的 APIrelative_url 将不太容易出错。
access_token
所有者决定谁是
me

其他想法:您是否使用

Facbook 调试器
检查了数据库中存储的 access_token 以确保它有效,实际上属于您期望的用户并且具有正确的权限?另外,您是否验证了存储的
uid
以确保其正确?

© www.soinside.com 2019 - 2024. All rights reserved.