Search code examples
c#facebooktagging

Tag a photo on facebook with C#?


Is there a bug to tag a photo on sdk? Because I read something, some people has same problem... and its new..

anyway.. I can tag photo on android and it works .. and now I am trying to tag a photo on c# but I got some errors.. now its "Invalid photo tag subject"

here is my c# code

        PhotoTag tags = new PhotoTag { tag_uid = "?????", x = "10", y = "10", tag_text ="heyy.."};
        List<PhotoTag> tagList = new List<PhotoTag>() { tags };
        var tagparameters =  JsonConvert.SerializeObject(tagList);
        var photoDetails = new Dictionary<string, object>();

        photoDetails.Add("tags", tagparameters);
        var fbResult = client.Post("/" + photoID+  "/tags", photoDetails);

//*************************************************************

public class PhotoTag
{
    public string tag_uid  { get; set; }
    public string tag_text { get; set; }
    public string x { get; set; }
    public string y { get; set; }
}

I read here https://developers.facebook.com/docs/reference/api/photo/

I used 'to' and 'id' instead of 'tag_uid' but I got another errors.. (It was like its not a valid parameter)

and here is output of parameters

[0] = {[tags, [{"tag_uid":"641194276","tag_text":"heyy..","x":"10","y":"10"}]]}

and here is my android code which works..

post a photo to friend's wall on facebook with android

well.. I have two questions

1- Where is my mistake in my C# code?

2- How can I tag more than one friends ??

on sdk page, there is PHOTO_ID/tags?tags=[{"id":"1234"}, {"id":"12345"}]
but as I explained, it doesnt work ...

thank you


Solution

  • Here my code there is working:

    private const string ExtendedPermissions = "user_about_me,user_photos,publish_stream";
    
    [HttpPost]
    [FacebookAuthorize(Permissions = ExtendedPermissions, LoginUrl = "/Home/LogOn?ReturnUrl=~/Home")]
    public ActionResult MensagemPost(string message)
    {
        var fb = new FacebookWebClient();
        dynamic me = fb.Get("me");
    
        string friendId_1 = // get the first one friend id
        string friendId_2 = // get the second one friend id
    
        var tags = new[] 
        { 
            new { tag_uid = friendId_1, x = 20, y = 20 },
            new { tag_uid = friendId_2, x = 40, y = 40 },
            new { tag_uid = (string)me.id, x = 60, y = 60 }
        };
    
        dynamic parameters = new ExpandoObject();
        parameters.message = message;
        parameters.tags = tags;
        parameters.url = "http://1.bp.blogspot.com/-evheT51sfeM/TlO_wZ8YDqI/AAAAAAAAA8I/fjlg0G8AgMY/s1600/The-best-top-hd-desktop-naruto-shippuden-wallpaper-naruto-shippuden-wallpapers-hd-11.jpg";
    
        dynamic result = fb.Post("me/photos", parameters);
    
        return RedirectToAction("Index", new { success = true });
    }