【问题标题】:Facebook C# SDK Upload Photos with TaggingFacebook C# SDK 上传带有标签的照片
【发布时间】:2011-03-07 10:02:15
【问题描述】:

如何使用 facebook c# sdk 标记照片。

这是我的代码(上传图片):

    var fbApp = new FacebookClient(Session["xAccessToken"].ToString());
    string xfilename = MergedCombinedImage.ImageUrl;
    xfilename = xfilename.Replace("images/temp/", "");
    var fbUpl = new Facebook.FacebookMediaObject
    {
        FileName = xfilename,
        ContentType = "image/jpg"
    };

    var bytes = System.IO.File.ReadAllBytes(Server.MapPath(MergedCombinedImage.ImageUrl));
    fbUpl.SetValue(bytes);
    var photoDetails = new Dictionary<string, object>();
    photoDetails.Add("message", "test"); 
    photoDetails.Add("image", fbUpl); 
    var fbResult = fbApp.Post(@"/" + albumID + @"/photos", photoDetails);
    var result = (IDictionary<string, object>)fbResult;
    var photoID = result["id"];

谢谢

乒乓

【问题讨论】:

    标签: c# facebook facebook-c#-sdk


    【解决方案1】:

    要标记你可以这样做(一个简单的例子):

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

    【讨论】:

      【解决方案2】:

      【讨论】:

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