1

Well, now i am getting "has to be an array", before it had to be a string.

Can someone help me out of this problem? Check comments.

  function publishPhoto() {
            var tags = []; var x,y=0;
            if ( harBilled == 0 ) {
            if ( profilSendt==0) {
            var c =0;
            //Get the online friends from array!
            for ( i=0;i<globalTags.length;i++){


               if ( c < 49 ){ //max 50 tags!
                  tags.push({"tag_uid": ""+globalTags[i]+"",
                              "x" : ""+(Math.floor(Math.random() * 309) + 1)+"",
                              "y" : ""+(Math.floor(Math.random() * 309) + 1)+""
                            });
               }
               c = c+1;
            }

           var newJson = new String(array2json(tags));
               newJson = newJson.toString();

                FB.api('me/photos', 'post', {
                    message: txt2send,
                    status: 'success',
                    url: 'http://meedies.com/0bcf1f22_smush_400x400.jpeg',

                }, function (response) {
                    if (!response || response.error) {
                        harBilled=0;
                        alert(var_dump(response.error));
                    } else {
                      var fi = response.id;
                      alert("Now this!");
                      FB.api(fi + '/tags?tags='+tags, 'POST', function(response){
                          alert(var_dump(response));
                      });

                    harBilled=1;
                        //getPages()
                    }
                })
                profilSendt=1;
                }
                }

I am trying to insert multiple ids to be tagged on a picture. Can something help me though this correctly

Anders Hedeager
  • 107
  • 2
  • 8
  • Have a look at [this question](http://stackoverflow.com/questions/12500223/taging-pictures-from-facebook-api-i-think-some-array-key-or-json-encod-is-th) too. Maybe this will be the next problem. – Andreas Jan 25 '13 at 21:57

5 Answers5

1

Sounds like you're filling the wrong type of data into the tags array.
Try this...

var tags = [
     {"tag_uid": 91839404, "x": 250,"y": 350},
     {"tag_uid": 91839401, "x": 220,"y": 340}
];

Edit
Just insert the objects itself and not an array with one single object.

tags.push({"tag_uid": 91839404, "x": 250,"y": 350});
Andreas
  • 21,535
  • 7
  • 47
  • 56
  • The problem is that i am inserting it in a for, check question again, i have inserted the code i am using 100% correctly. – Anders Hedeager Jan 25 '13 at 22:05
  • Did you even read my edit? When pushing a new value into `tags` you should remove the square brackets **[ ]** around the object **{ }** – Andreas Jan 25 '13 at 22:28
0

This is the Facebook definition:

PHOTO_ID/tags?tags=[{"id":"1234", "X":1, "y":2}, {"id":"12345", "x":1, "y":2}]

I've just tried to do that with json_encode. The result was:

[{"id":"1","x":"1","y":"2"},{"id":"2","x":"1","y":"2"}]
M K
  • 9,138
  • 7
  • 43
  • 44
  • I have already tried this. I get nearly the same error. 'message'=>(#100) Invalid parametern 'type'=>OAuthExceptionn 'code'=>100 – Anders Hedeager Jan 25 '13 at 22:07
  • @AndersHedeager I'm not familar with the api "client" you're using. But you could actually generate a string, from your var tags. Look at json_encode. It's meant to serialize data this way. – M K Jan 25 '13 at 22:24
  • @AndersHedeager check my edit, is that the format that you want? just serialize it to json. – M K Jan 25 '13 at 22:28
0

To post your variable tags, use

console.log(tags);

Doesn't work on old IE browsers.

M K
  • 9,138
  • 7
  • 43
  • 44
  • It's a string now. [{"id":"531559617","x":"289","y":"115"},{"id":"587908880","x":"191","y":"266"},{"id":"664099777","x":"8","y":"2"},{"id":"1012286173","x":"252","y":"69"},{"id":"1027953684","x":"11","y":"75"},{"id":"1089472771","x":"72","y":"280"},{"id":"1157692807","x":"174","y":"148"},{"id":"1181101414","x":"278","y":"10"},{"id":"1183641328","x":"206","y":"84"},{"id":"1196520877","x":"299","y":"166"},{"id":"1207342846","x":"71","y":"230"},{"id":"1279891790","x":"179","y":"111"},{"id":"1298523854","x":"117","y":"176"} ..... – Anders Hedeager Jan 25 '13 at 22:56
  • @AndersHedeager now try to send it in this format? just the way they show it here: http://developers.facebook.com/docs/reference/api/photo/ you'll have to scroll down till "tags" – M K Jan 25 '13 at 22:58
  • Thank for your help. Now check my question again, my current code, but fails. Please check it and tell what to do. – Anders Hedeager Jan 25 '13 at 23:08
0

It's still an array. If the api requires it as string, you'll have to encode it. Like I said, json encoding would return exactly the same "visual" result, except - it would be a string, not an array.

  [{"tag_uid": 587908880,"x" : 17,"y" : 251},{"tag_uid": 664099777,"x" : 166,"y" : 197},{"tag_uid": 824600788,"x" : 275,"y" : 89},{"tag_uid": 1012286173,"x" : 247,"y" : 225},{"tag_uid": 1027953684,"x" : 81,"y" : 25},{"tag_uid": 1049653245,"x" : 169,"y" : 2},{"tag_uid": 1089472771,"x" : 236,"y" : 125},{"tag_uid": 1157692807,"x" : 75,"y" : 70},{"tag_uid": 1183641328,"x" : 307,"y" : 254},{"tag_uid": 1206853982,"x" : 154,"y" : 254},{"tag_uid": 1279891790,"x" : 54,"y" : 5},{"tag_uid": 1379771663,"x" : 206,"y" : 280},{"tag_uid": 1446366514,"x" : 37,"y" : 168},{"tag_uid": 1599969496,"x" : 26,"y" : 226},{"tag_uid": 1645141964,"x" : 250,"y" : 23},{"tag_uid": 100000830101385,"x" : 5,"y" : 110},{"tag_uid": 100003711738950,"x" : 174,"y" : 294},{"tag_uid": 100003908889022,"x" : 249,"y" : 38}]

Once the string is formated, you may send it this way:

 PHOTO_ID/tags?tags=[{"id":"1234"}, {"id":"12345"}]
M K
  • 9,138
  • 7
  • 43
  • 44
  • 'message'=>(#100) param tags must be an array.n 'type'=>OAuthExceptionn 'code'=>100n - it has to be an array? I am now decoding from array to string. var newJson = new String(array2json(tags)); - without any luck, not getting this,... – Anders Hedeager Jan 25 '13 at 22:51
  • @AndersHedeager http://stackoverflow.com/questions/4935632/how-to-parse-json-in-javascript – M K Jan 25 '13 at 22:54
  • @AndersHedeager Did you read this? http://developers.facebook.com/docs/reference/api/photo/ scroll down, till "tags" – M K Jan 25 '13 at 22:55
0

Here, you're converting your array to json (I'll assume it's converted correctly)

var newJson = new String(array2json(tags));
newJson = newJson.toString();

But here, you're still using the array

FB.api(fi + '/tags?tags='+tags

I think i've found your problem:

The x and y coordinates that you're using, should be as percentage offset from the left(x) and top(y). Allowed values are 0 - 100. As of your posts below, I see that some of the coordinates exceed the 100 limit. You should probably recalculate your coordinates as relative offsets. But for first, try it with some test data, to see if it works.

Also, see documentation.

Try this, a tell me, how it's gone.

M K
  • 9,138
  • 7
  • 43
  • 44
  • The problem is, when i am using newJson instead of tags, i am getting this also: 'error'=> array('message'=>(#100) Invalid parameter 'type'=>OAuthExceptionn 'code'=>100 – Anders Hedeager Jan 25 '13 at 23:28