如何发布照片和标记朋友 - 使用Facebook sdk

时间:2012-10-25 13:51:43

标签: c# facebook post sdk photo

我正在使用Facebook C# SDK

问题:

'发布照片,但不是“标签”

public JsonResult PostFacebookTagPhoto()
{
    var path = Request["url"];
    var tag = Request["tags"];

    var facebookClient = new FacebookClient(Session["facebook.accessToken"].ToString());
    var file = new FileInfo(path);

    var data = System.IO.File.ReadAllBytes(file.FullName);

    var stream = System.IO.File.OpenRead(path);

    try
    {
        var itens = JsonHelper.JsonDeserialize<List<TagFacebook>>(tag);
        dynamic me = Session["facebook.me"];
        var tags = new[] 
        { 
            new { itens[1].tag_uid, x = 30, y = 40},
            new { itens[2].tag_uid, x = 40, y = 50},
            new { itens[3].tag_uid, x = 30, y = 40},
            new { itens[4].tag_uid, x = 40, y = 50},
            new { tag_uid = (string)me.id, x = 50, y = 40}
        };

        dynamic parameters = new ExpandoObject();
        parameters.message = GetFacebookMessage();
        parameters.tags = tags;
        parameters.file = new FacebookMediaObject
        {
              ContentType = MimeTypes.GetMimeType(file.Extension.ToLowerInvariant()),
              FileName = file.Name.ToLowerInvariant()
        }.SetValue(data);
        try
        {
            facebookClient.Post("/me/photos", parameters); //LINE 133
        }
        catch (FacebookApiException ex)
        {
            return new JsonResult { Data = new { status = "error", message = ex.Message, source = ex.Source, stacktrace = ex.StackTrace }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        //SalvaDados(me, itens);

        return new JsonResult { Data = new { status = "ok" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    }
    catch (FacebookOAuthException ex)
    {
        return new JsonResult { Data = new { status = "error", message = ex.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    }
}

错误MESSGAE:

  

(例外 - #1399017)抱歉,发生错误。请再试一次。

堆栈追踪:

  

在Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper,String responseString,Type resultType,Boolean containsEtag,IList`1 batchEtags)
  在Facebook.FacebookClient.Api(HttpMethod httpMethod,String path,Object parameters,Type resultType)
  在Facebook.FacebookClient.Post(字符串路径,对象参数)
  at(...)\ Controllers \ SiteController.cs:第133行

0 个答案:

没有答案