0

我正在尝试标记图片并通过图表发布但是,当我'tags' => $tags从下面删除时,它可以工作。否则我会收到此错误:

Array ( [error] => Array ( [message] => (#100) param tags must be an array. [type] => OAuthException [code] => 100 ) )

这是我的代码:

<?php
$tags = array(
    'to' => $_SESSION['my_fb_id'],
    'x' => 0,
    'y' => 0
);

 $tag[]= $tags ;
//
//upload photo
$file = 'imgtmp/save_as_this_name.jpg';
$args = array(
    'message' => 'This is my Picture',
    'tags' => $tag, // IF this line is removed ,It works!
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token=' . $_SESSION['access_token'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
print_r(json_decode($data, true));
?>
4

2 回答 2

2

标签必须是标签数组,因为您可以标记很多人。

$tag1 = array(
    'tag_text' => 'tag test1',
    'tag_uid' => 'XXXXX1',
    'x' => 0,
    'y' => 0
);

$tag2 = array(
    'tag_text' => 'tag test2',
    'tag_uid' => 'XXXXX2',
    'x' => 0,
    'y' => 0
);

$tags = array($tag1, $tag2);

在你的情况下

$args = array(
    'message' => 'This is my Picture',
    'tags' => array( $tags ) , 
);

编辑1:

要成功标记照片,您需要user_photos获得许可。

使用图形 API

$file = 'test.jpg';
$tags = array(
    'tag_text' => 'tag test',
    'tag_uid' => 'XXXXX',
    'x' => 10,
    'y' => 10
);

$args['tags'] = array($tags);
$args[basename($file)] = '@' . realpath($file);
$data = $facebook->api("/me/photos", "post", $args);

print_r($data);

编辑2:

只需将 json_encode 用于 tags 参数

$args['tags'] = json_encode(array($tags));

这将解决使用 cURL 时的问题。

于 2012-09-09T05:18:27.440 回答
0

好吧,我明白了。来自 Facebook API:

"tags": {
            "data": [
               {
                  "id": "11111111111111",
                  "name": "John Doe",
                  "x": 0,
                  "y": 0,
                  "created_time": "2012-09-03T03:08:44+0000"
               }
            ]
         },

标签 arg 需要包含一个以data作为键的数组。这里:

$tags['data'] = array('to' => $_SESSION['my_fb_id'], 'x' => 0, 'y' => 0);

于 2012-09-09T04:54:05.220 回答