2012-09-06 44 views
0

在Facebook中添加鏈接帖子時,會自動在帖子中添加一個漂亮的描述(包含鏈接頁面中的文本片段)和縮略圖。Facebook API可用於創建帶摘要的鏈接帖子嗎?

有沒有辦法使用Facebook API自動執行此操作?我傾向於認爲沒有,因爲使用Facebook API do not contain descriptions的流行Web應用程序IFTTT添加的帖子。我不清楚這是否是Facebook API的限制,以及是否有任何解決方法。

回答

2

是的,這是可能的。您可以使用Graph Api方法/profile_id/feed。該方法接收參數消息,圖片,鏈接,名稱,標題,說明,來源,地點和標籤。 facebook以「漂亮的總結和縮略圖」組織參數。

你可以在出版科的詳細信息中的鏈接http://developers.facebook.com/docs/reference/api/

在C#:

 public static bool Share(string oauth_token, string message, string name, string link, string picture) 
     { 
      try 
      { 
       string url = 
        "https://graph.facebook.com/me/feed" + 
        "?access_token=" + oauth_token; 

       StringBuilder post = new StringBuilder(); 
       post.AppendFormat("message={0}", HttpUtility.UrlEncode(message)); 
       post.AppendFormat("&name={0}", HttpUtility.UrlEncode(name)); 
       post.AppendFormat("&link={0}", HttpUtility.UrlEncode(link)); 
       post.AppendFormat("&picture={0}", HttpUtility.UrlEncode(picture)); 

       string result = Post(url, post.ToString()); 
      } 
      catch (Exception) 
      { 
       return false; 
      } 

      return true; 
     } 

     private static string Post(string url, string post) 
     { 
      WebRequest webRequest = WebRequest.Create(url); 
      webRequest.ContentType = "application/x-www-form-urlencoded"; 
      webRequest.Method = "POST"; 

      byte[] bytes = Encoding.ASCII.GetBytes(post); 

      webRequest.ContentLength = bytes.Length; 

      Stream stream = webRequest.GetRequestStream(); 
      stream.Write(bytes, 0, bytes.Length); 
      stream.Close(); 

      WebResponse webResponse = webRequest.GetResponse(); 

      StreamReader streamReader = new StreamReader(webResponse.GetResponseStream()); 

      return streamReader.ReadToEnd(); 
     } 

UPDATE:

的Open Graph協議的meta標籤:http://developers.facebook.com/docs/opengraphprotocol/

+0

而Facebook會自動抓取描述 - 您不必親自獲取並通過它在'description'參數中? – Eric

+1

嗯,它沒有很好的記錄,但有時當我發送一個鏈接Facebook做的工作,有時不(我認爲它只適用於該網站有開放圖協議元標籤實施,但我不知道這一點)。爲了完全控制輸出,您必須發送所有內容。因爲我在自己的網站上做這件事,所以我需要在變量中使用所有字段,所以發送所有內容都不是問題。 – lolol

相關問題