在Facebook Wall上发布照片和视频

时间:2014-03-06 06:53:19

标签: c# asp.net-mvc facebook facebook-graph-api

我需要从我的MVC应用在Facebook墙上发布照片,视频。我低于错误 (OAuthException - #2500) An active access token must be used to query information about the current user.

请帮帮我。请在下面找到我正在使用的代码。

  string appID = string.Empty;
  string appSecretCode = string.Empty;
  appID = "<<application Id>>";
  appSecretCode = "<<app secretcode>>";
  var fb = new FacebookClient();
  dynamic result = fb.Get("oauth/access_token", new
  {
      client_id = appID,
      client_secret = appSecretCode,
      grant_type = "client_credentials",
      scope = "publish_stream"
  });
  string accessToken = result.access_token;
  var client = new FacebookClient(accessToken);
  var postparameters = new Dictionary<string, object>();
  var media = new FacebookMediaObject
  {
      FileName = @"Bday.jpg",
      ContentType = "image/jpeg"
  };
  byte[] img = System.IO.File.ReadAllBytes(@"C:\Users\user\Desktop\Bday.jpg");
  media.SetValue(img);
  postparameters["source"] = media;
  postparameters["access_token"] = result.access_token;
  var result1 = client.Post(String.Format("https://graph.facebook.com/{0}/photos", "<<User ID>>"), postparameters); 

1 个答案:

答案 0 :(得分:0)

您需要从https://developers.facebook.com/tools/explorer生成访问令牌并尝试:

required AcccountId, pageid

dynamic parameters = new ExpandoObject();
parameters.message =modelList.message;
parameters.subject = modelList.subject;
parameters.account_id = modelList.AcccountId;

imageBytes =  byte[] of image

parameters.source = new FacebookMediaObject{
    ContentType = imageType,
    FileName = Url
}.SetValue(imageBytes);

client.Post(pageid+ "/photos", parameters);

希望它会有所帮助。