2011-07-26 73 views
2

我需要發佈一個帖子我的應用程序的個人資料頁上的應用程序的應用程序並不像這裏的用戶是代碼:Facebook應用程序頁面上發佈爲使用Facebook的C#SDK

var fb = new FacebookOAuthClient(FacebookApplication.Current); 
      dynamic resultt = fb.GetApplicationAccessToken(); 
      var appAccessToken = resultt.access_token; 
      dynamic messagePost = new ExpandoObject(); 
      messagePost.access_token = appAccessToken; 
      messagePost.picture = ""; 
      messagePost.link = ""; 
      messagePost.name = "[SOME_NAME]"; 
      messagePost.caption = "{*actor*} " + "[YOUR_MESSAGE]"; //<---{*actor*} is the user (i.e.: Aaron) 
      messagePost.description = "[SOME_DESCRIPTION]"; 

      FacebookClient appp = new FacebookClient(appAccessToken); 

      try 
      { 
       var result = appp.Post("/" + appId + "/feed", messagePost); 
      } 
      catch (FacebookOAuthException ex) 
      { 
       //handle something 
      } 
      catch (FacebookApiException ex) 
      { 
       //handle something else 
      } 

or 
    var fb = new FacebookClient(appId, FacebookApplication.Current.AppSecret); 
      var appAccessToken = fb.AccessToken; 

回答

1

這裏是代碼:

var fb = new FacebookOAuthClient(FacebookApplication.Current); 
      dynamic resultt = fb.GetApplicationAccessToken(); 
      var appAccessToken = resultt.access_token; 

      dynamic messagePost = new ExpandoObject(); 
      messagePost.access_token = appAccessToken; 
      messagePost.picture = "http://www.destination360.com/europe/sweden/images/s/sweden-visby.jpg"; 
      messagePost.link = "http://www.destination360.com/europe/sweden/images/s/sweden-visby.jpg"; 
      messagePost.name = "[SOME_NAME]"; 
      messagePost.caption = "{*actor*} " + "[YOUR_MESSAGE]"; 
      messagePost.description = "[SOME_DESCRIPTION]"; 
      messagePost.from = AppId; 
      messagePost.to = "130736200342432"; 
      FacebookClient appp = new FacebookClient(appAccessToken); 
      var result = appp.Post("/" + AppId + "/feed", messagePost); 
相關問題