facebook-graph-api - 无法在 Facebook 页面 PHP SDK Graph API 上标记用户

标签 facebook-graph-api upload tags tagging facebook-page

我试图编写一个脚本,允许用户在我网站上显示的照片上标记自己。

一旦用户选择了要标记的人,照片就会上传到我网站的 Facebook 粉丝页面,但 Facebook 不允许我的应用使用当前登录的用户 profile_id 或他们任何 friend 的照片来标记照片。

除了添加标签外,一切都很好。我得到错误:
fatal error :未捕获的 OAuthException:发生未知错误。在第 1039 行抛出/home/public_html/include/api/facebook.3.0.1/base_facebook.php

这是到目前为止的代码:

<?php
require_once ($_SERVER['DOCUMENT_ROOT'] . "/include/api/facebook.3.0.1/facebook.php");

//Name of album you want to create
$album_name = "December 4, 2011";

// Create our application instance
// (replace this with your appId and secret).
$facebook = new Facebook(array(
        'appId' => 'APP_ID_INSERT_HERE',
        'secret' => 'APP_SECRET_INSERT_HERE',
    ));

$facebook->setFileUploadSupport(true);


// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based 
// on whether the user is logged in.
// If we have a $user id here, it means we know 
// the user is logged into
// Facebook, but we don’t know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

if ($user) {

// Get access token for Facebook Page
$page_id = '170367249680012';
$page_info = $facebook->api("/$page_id?fields=access_token");

if (!empty($page_info['access_token'])) {

    $param = array(
        'method' => 'fql.query',
        'query' => 'SELECT object_id FROM album WHERE owner="FACEBOOK_PAGE_ID_INSERT_HERE" AND name="' . $album_name . '"'
    );
    //Check if album exists
    $album = $facebook->api($param);

    if (isset($album[0]['object_id'])) {
        // If album exists store id in the variable $album_uid
        $album_uid = $album[0]['object_id'];
    } else {

        // ELSE Create album
        $album_details = array(
            'access_token' => $page_info['access_token'],
            'message' => 'Album desc',
            'name' => $album_name
        );

        $create_album = $facebook->api('/me/albums', 'post', $album_details);

        //Get album ID of the album you've just created
        $album_uid = $create_album['id'];
    }

    //Photo Details

    $file = 'test.jpg'; //Example image file
    $photo_details['image'] = '@' . realpath($file);

    //Upload a photo to album

    $args = array(
        'access_token' => $page_info['access_token'],
        'image' => '@' . realpath($file),
        'message' => "test"
    );


    $upload_photo = $facebook->api('/' . $album_uid . '/photos', 'post', $args);

    //Get id of photo uploaded
    $photo_id = $upload_photo['id'];

    echo "<br/>" . $photo_id . "<br/>";


//ADD TAGS

    $argstag = array('to' => $user);
    $argstag['x'] = 40;
    $argstag['y'] = 40;
    $datatag = $facebook->api('/' . $photo_id . '/tags', 'post', $argstag);
    }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
} else {
    $loginUrl = $facebook->getLoginUrl(array('scope' => 'status_update,publish_stream,user_photos,offline_access,manage_pages'));
}

?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <title>php-sdk</title>
    <style>
      body {
        font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
      }
      h1 a {
        text-decoration: none;
        color: #3b5998;
      }
      h1 a:hover {
        text-decoration: underline;
      }
    </style>
  </head>
  <body>
    <h1>php-sdk</h1>

    <?php if ($user): ?>
      <a href="<?php echo $logoutUrl; ?>">Logout</a>
    <?php else: ?>
      <div>
        Login using OAuth 2.0 handled by the PHP SDK:
        <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
      </div>
    <?php endif ?>

  </body>
 </html>

有趣的是,如果我使用相同的脚本将图像上传到用户个人资料并标记它可以工作的图像!

对于那些想要这样做的人,请删除以下代码行,它会出现两次
'access_token' => $page_info['access_token'],

并改变
$upload_photo = $facebook->api('/' . $album_uid . '/photos', 'post', $args);


$upload_photo = $facebook->api('/me/photos', 'POST', $args);

我已经到处搜索,看看是否有限制阻止 API 允许用户在粉丝页面上标记自己或 friend ,但我找不到任何东西。我唯一能找到的是:

http://forum.developers.facebook.net/viewtopic.php?id=101485

所以我不确定这是否是正式的错误,但我似乎遇到了与他们相同的问题。它是在 6 个月前作为错误提交的,似乎没有任何进展。

有谁知道这个问题的解决方法?我不想将图像上传到用户个人资料并对其进行标记。

最佳答案

检查您的页面设置。有一个设置允许粉丝在照片中标记自己。确保其已启用并重试。寻找 Tagging AbilityManage Permissions 下设置.

关于facebook-graph-api - 无法在 Facebook 页面 PHP SDK Graph API 上标记用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8425605/

相关文章:

facebook - 如何使用 Graph API 将带有图片的链接发布到 Facebook?

facebook - 到期后如何在不重新加载页面的情况下获得新的访问 token ?

facebook-graph-api - Instagram Graph API - 当用户从个人帐户切换到企业帐户时获取媒体洞察指标

php - 安全的 PHP 文件上传脚本

jquery - 如何显示当前上传进度(jquery + post + php)?

node.js - 使用expressjs multer时xhr上传进度

tags - 类别、标签或两者兼而有之?

javascript - 使用替代文本查找图像标签

mysql - 处理表格的困境?

api - 新字段 'new_like_count' 是什么?