2014-01-05 69 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 –