我正在尝试标记图片并通过图表发布但是,当我从下面删除'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));
?>
答案 0 :(得分: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
权限。
使用graph 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作为标签参数
$args['tags'] = json_encode(array($tags));
这将解决使用cURL时的问题。
答案 1 :(得分: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'=&gt; $ _SESSION [ 'my_fb_id'], 'x'=&gt; 0, 'y'=&gt; 0);