2014-01-05 65 views
0

我試圖張貼在用戶牆上的照片和標記在那張照片中的朋友。我有發佈流和照片的用戶的權限。現在我使用fb.api方法在用戶牆上貼標籤並標記朋友。我的代碼工作正常,如果我定義將在該照片中標記的用戶ID,但我想這樣做自動,我試過這些代碼,但這是行不通的,因爲一些錯誤,請任何人都幫我修復代碼。使用javascript sdk上傳照片和標記的朋友

// Auto post picture of talent result 
     FB.api('/me/photos', 'post', { 
     access_token: response.authResponse.accessToken, 
     url: 'http://guthrienewspage.files.wordpress.com/2013/10/talent.jpg', 
     message: 'this is my new talent that i discovered', 
     tags: '[{tag_uid:12312,x:20,y:20},{tag_uid:34212,x:20,y:20},{tag_uid:123122132,x:20,y:20}]' 
     }, function(response) { 
     if (!response || response.error) { 
     alert('Error occured'); 
     } else { 
     alert('Post ID: ' + response.id); 
     } 
     }); 

上面的代碼現在工作properply我用下面的代碼來獲取用戶的朋友ID:

FB.api('/me/friends', function(response) { 
      if(response.data) { 
      $.each(response.data,function(index,friend) { 
     // friendidtag = {tag_uid: + friend.id + ,x:20,y:20}, 
     // alert(friend.name + ' has id:' + friend.id); 
     var alltagsid = '{tag_uid: + friend.id + ,x:20,y:20},'; 
      }); 
      } else { 
       alert("Error!"); 
       } 
     }); 

,然後使用該變種alltagsid在我的第一個這樣的代碼:

// Auto post picture of talent result 
    FB.api('/me/photos', 'post', { 
    access_token: response.authResponse.accessToken, 
    url: 'http://guthrienewspage.files.wordpress.com/2013/10/talent.jpg', 
    message: 'this is my new talent that i discovered', 
    tags: '[alltagsid]' 
    }, function(response) { 
    if (!response || response.error) { 
    alert('Error occured'); 
    } else { 
    alert('Post ID: ' + response.id); 
    } 
    }); 

但這不工作plz幫我解決這段代碼。並且請不要給我提供api的參考資料,只是讓這些代碼得到修正併發布答案,如果你能以其他方式離開它的話。

+0

有人回覆plz :((((((( –

回答

0

在Javascript中的數組聲明就是這樣。檢查它

FB.api('/me/friends', function(response) { 
     if(response.data) { 
     $.each(response.data,function(index,friend) { 
    // friendidtag = {tag_uid: + friend.id + ,x:20,y:20}, 
    // alert(friend.name + ' has id:' + friend.id); 
    var alltagsid = new array '{tag_uid: + friend.id + ,x:20,y:20},'; 
     }); 
     } else { 
      alert("Error!"); 
      } 
    }); 
+0

NOT WORKING :(s –