【问题标题】:Upload photo and tag friends using javascript sdk使用 javascript sdk 上传照片和标记朋友
【发布时间】:2014-01-05 13:43:42
【问题描述】:

我正在尝试在用户墙上发布照片并在该照片中标记他们的朋友。我拥有发布流和照片用户的权限。现在我正在使用 fb.api 方法在用户墙上发帖并标记朋友。如果我定义将在该照片中标记的用户 ID,我的代码可以正常工作,但我想自动执行此操作,我尝试了这些代码,但由于一些错误,这不起作用,请任何人帮助我修复代码。

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

上面的代码工作正常,现在我使用下面的代码来检索用户朋友 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!");
              }
         });

然后在我的第一个代码中使用这个 var 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);
    }
    }); 

但这不起作用请帮助我修复此代码。请不要给我 api 的参考,只要修复此代码并发布答案,如果你可以离开它。

【问题讨论】:

  • 有人回复plz :((((((

标签: javascript facebook facebook-graph-api sdk


【解决方案1】:

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!");
          }
     });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多