2012-09-09 83 views
0

我試圖標記圖片並通過圖表發佈但是,當我從下面刪除'tags' => $tags時,它可以正常工作。否則,我得到這個錯誤:在Facebook上標記朋友通過圖形

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

回答

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標籤爲參數

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

這將同時使用捲曲解決問題。

+0

它沒有工作阿布舍克。 – Yahoo

+0

問題是'user_photos'權限,你需要它來標記照片。我已經使用此權限對它進行了測試,並且工作正常。 – Abhishek

+0

我也有'user_photos'權限... 但我沒有使用'$ data = $ facebook-> api(「/ me/photos」,「post」,$ args);' 我是用'Curl'做這個。這是否會造成問題?你怎麼能編輯使用'curl' – Yahoo

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

+0

我會試試看。問題:如果我想給人貼標籤? '''=> $ _SESSION ['my_fb_id'],'x'=> 0,'y'=> 0'],['to'=> $ _SESSION ['my_fb_id2' ],'x'=> 0,'y'=> 0']); – Yahoo

+0

它沒有工作。 – Yahoo

+0

是的,它存在。我可以發佈圖片,如果我刪除了''tags'=> $ tags,'行 – Yahoo

相關問題