是否可以从https://www.facebook.com/{REFERENCED_PAGE_ID}/posts/{SOME_OTHER_ID}
表单后面的链接而不是典型表单https://www.facebook.com/{POSTER_ID}/posts/{POST_ID}
获取永久链接(可以成功嵌入)到facebook帖子?如果是这样,怎么办呢?
给出如下链接(无法正确嵌入) https://www.facebook.com/209447300380/posts/10153494075900381
我需要能够以编程方式生成以下可嵌入的链接 https://www.facebook.com/photo.php?fbid=10151668558417282&set=a.244117472281.146601.8128837281&type=1
通常解决方案是使用语句
查询facebookselect permalink from stream where post_id='209447300380_10153494075900381'
但是此查询不会为我生成任何数据。我怀疑原始链接存在问题:209447300380
不是发布页面的ID,而是被引用页面的ID。如果209447300380
是发布页面的ID,我可以从Facebook获得永久链接而不会出现任何问题。
答案 0 :(得分:2)
它看起来像一个bug。使用FQL获取永久链接不起作用,而它适用于Graph API。您应该使用Graph API:
https://graph.facebook.com/209447300380_10153494075900381?fields=link&access_token=YOUR_TOKEN
结果:
{
"link": "https://www.facebook.com/photo.php?fbid=10151668558417282&set=a.244117472281.146601.8128837281&type=1",
"id": "209447300380_10153494075900381",
"created_time": "2013-11-08T18:08:46+0000"
}
我想,使用Graph API不会对您的应用做太多更改。
答案 1 :(得分:0)
不幸的是,我们发现找出可嵌入链接最可靠的方法就是尝试访问起始链接,然后按照重定向的位置进行操作。如果重定向在facebook.com/login结束,那么它无法嵌入(无论如何都是公开的)。否则,最终应该达到可嵌入链接。
C#示例:
public static string GetPermalink (string url) {
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest) WebRequest.Create (url);
request.Method = "HEAD";
request.AllowAutoRedirect = true;
request.UserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) Chrome/24.0.1304.0 Safari/537.16";
try { response = request.GetResponse () as HttpWebResponse; }
catch (WebException ex) { response = ex.Response as HttpWebResponse; }
using (response) {
string responseUri = null == response.ResponseUri ? null : response.ResponseUri.AbsoluteUri;
if (HttpStatusCode.OK == response.StatusCode) {
/* Ended at a login page. This post isn't viewable to the public. */
if (responseUri.StartsWith (@"https://www.facebook.com/login.php?") ||
responseUri.StartsWith (@"http://www.facebook.com/login.php?")) {
return null;
}
/* Found a public post. */
else return responseUri;
}
else return null;
}
}