Facebookにリンク投稿を追加すると、見栄えの良い説明(リンクされたページのテキストのスニペットを含む)とサムネイルが自動的に投稿に追加されます。
Facebook APIを使用してこれを自動的に行う方法はありますか?Facebook APIを使用する人気のあるWebアプリケーションであるIFTTTによって追加された投稿には説明が含まれていないため、存在しないと思う傾向があります。これがFacebookAPIの制限であるかどうか、そしてそれを回避する方法があるかどうかはわかりません。
Facebookにリンク投稿を追加すると、見栄えの良い説明(リンクされたページのテキストのスニペットを含む)とサムネイルが自動的に投稿に追加されます。
Facebook APIを使用してこれを自動的に行う方法はありますか?Facebook APIを使用する人気のあるWebアプリケーションであるIFTTTによって追加された投稿には説明が含まれていないため、存在しないと思う傾向があります。これがFacebookAPIの制限であるかどうか、そしてそれを回避する方法があるかどうかはわかりません。
はい、可能です。GraphApiメソッドを使用できます/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();
}
アップデート:
オープングラフプロトコルメタタグ:http ://developers.facebook.com/docs/opengraphprotocol/