回答
這是一個新的方法來獲得一個大的圖像。它誕生的預覽方法不適用
/**
* return a big url of facebook
* works onky for type PHOTO
* @param picture
* @param is a post type link
* @return url of image
*/
@Transactional
public String getBigImageByFacebookPicture(String pictrue,Boolean link){
if(link && pictrue.contains("url=http")){
String url = pictrue.substring(pictrue.indexOf("url=") + 4);
try {
url = java.net.URLDecoder.decode(url, "UTF-8");
} catch (UnsupportedEncodingException e) {
StringBuffer sb = new StringBuffer("Big image for Facebook link not found: ");
sb.append(link);
loggerTakePost.error(sb.toString());
return null;
}
return url;
}else{
try {
Document doc = Jsoup.connect(pictrue).get();
return doc.select("#fbPhotoImage").get(0).attr("src");
} catch (Exception e) {
StringBuffer sb = new StringBuffer("Big image for Facebook link not found: ");
sb.append(link);
loggerTakePost.error(sb.toString());
return null;
}
}
}
後享受您的大圖像:)
你的答案爲我解決了這個問題,我推薦給大家 – TooCooL 2014-09-23 23:01:36
我問了這個問題,現在看來,你的答案似乎是最好的解決方案。做得好。 – user1105951 2014-10-11 10:00:05
所有使用此答案,並希望刪除130x130無論它是130x130或s433x23或p43x43 檢查此: http://stackoverflow.com/questions/26313382/remove-dynamic-substring-from-string/26313575 #26313575 – user1105951 2014-10-11 10:47:14
什麼工作對我來說: 充分利用飼料中的圖片鏈接,並以「_n.jpg
」
我不得不訴諸於此,但它感覺真的很髒並且很脆弱。仍在尋找更好的方法。 – 2012-08-23 09:44:47
不錯,它的工作。我覺得n代表正常,而我把b我得到了更大的一個。 – 2013-08-10 09:49:27
我不得不訴諸於此。 Facebook並沒有在它的API中提供這種明顯必要的功能,這真是令人遺憾。 – jokeefe 2013-12-06 03:18:51
OK取代「_s.jpg
」,我發現了一個更好的辦法。當您使用圖API檢索供稿時,任何類型爲photo
的供稿項目都將有一個名爲object_id
的字段,該字段不是純粹的status
類型項目。用該ID查詢Graph API,例如https://graph.facebook.com/1234567890
。請注意,對象ID不是下劃線分隔的值,例如該Feed項目的主ID。
object_id
查詢的結果將是一個新的JSON字典,其中包含一個source
屬性,該屬性包含的圖像的URL至今足以滿足我的需求。
另外還有一個images
數組,其中包含更多用於圖像大小不同的圖像URL,但其中的大小看起來並不可預測,並且實際上並不都與圖像後面的物理尺寸相對應URL。
我仍然希望有一種方法可以通過一個Graph API調用來實現,但看起來並不存在。
的Graph API photo object具有picture
連接(類似於用戶對象具有):
「照片的專輯尺寸圖。 [...]返回:HTTP 302重定向到圖片的URL「
所以請求https://graph.facebook.com/{object-id-from-feed}/picture
將立即重定向到照片的相冊大小的版本。 (有用的不僅是在瀏覽器中顯示出來,而且如果FE要圖像下載到您的服務器,使用cURL與follow_redirect選項集。)
編輯:
與開始API v2.3,供稿帖子的/picture
邊緣已被棄用。
但是,作爲字段仍然可以請求圖片 - 但它會是一個小圖片。
但是full_picture
也可以使用。
所以/{object-id-from-feed}?fields=picture,full_picture
可以用來請求那些,或者他們可以直接請求與其他的feed數據,就像這樣/page-id/feed?fields=picture,full_picture,…
(附加字段,如消息等,必須用相同的方式指定。)
工作形式我。不需要每個帖子的api facebook :) – Marcelo 2013-07-31 21:00:41
這是真正的交易。不要亂用絕對文件url的 – user1576978 2014-12-10 18:48:03
這很奇妙 – 2015-01-20 17:38:47
對於來自高分辨率圖像鏈接:
- 鏈接的帖子
- 視頻帖子
- 照片的帖子
我使用以下命令:
注:的我給了_s -> _o
hack precedenc e通過object_id/picture
方法是因爲object_id方法沒有返回所有圖像的結果。
var picture = result.picture;
if (picture) {
if (result.type === 'photo') {
if (picture.indexOf('_s') !== -1) {
console.log('CONVERTING');
picture = picture.replace(/_s/, '_o');
} else if (result.object_id) {
picture = 'https://graph.facebook.com/' + result.object_id + '/picture?width=9999&height=9999';
}
} else {
var qps = result.picture.split('&');
for (var i = 0; i < qps.length; i++) {
var qp = qps[i];
var matches = qp.match(/(url=|src=)/gi);
if (matches && matches.length > 0) picture = decodeURIComponent(qp.split(matches[0])[1]);
}
}
}
這非常有效。你可以建立一個檢查,如果圖片無法從_s更改爲_o或_n(容易使用Picasso)加載,只需獲取對象ID並通過另一個API調用從那裏獲取源代碼。 – Wenger 2014-05-01 13:31:38
好的建議!我並不真的需要這種功能,但對於真正需要最大圖像的人來說,這是一個好主意。 – mattdlockyer 2014-05-01 23:40:30
這很棒!非常感謝! – jokeefe 2014-06-04 20:55:38
感謝@mattdlockyer的JS解決方案。這裏是一個類似的東西在PHP:
$posts = $facebook->api('/[page]/posts/', 'get');
foreach($posts['data'] as $post)
{
if(stristr(@$post['picture'], '_s.'))
{
$post['picture'] = str_replace('_s.', '_n.', @$post['picture']);
}
if(stristr(@$post['picture'], 'url='))
{
parse_str($post['picture'], $picturearr);
if($picturearr['url'])
$post['picture'] = $picturearr['url'];
}
//do more stuff with $post and $post['picture'] ...
}
其實,你需要兩個不同的解決方案,以充分解決這個問題。
1] https://graph.facebook.com/ {OBJECT_ID} /圖片
這個解決方案工作正常發佈至Facebook的圖片和視頻,但遺憾的是,它的情況下,原始圖像文件並沒有直接上傳至Facebook返回小圖片。 (例如,在您的頁面上發佈指向其他網站的鏈接時)。
2] Facebook Graph API提供了一種獲取Feed中的完整圖像的方法,用於這些外部鏈接。如果您在調用API時將'full_picture'添加到以下示例中的字段中,則會提供指向更高分辨率版本的鏈接。
結合這兩個解決方案,我結束了在過濾PHP中輸入如下:
if (isset($post['object_id'])){
$image_url = 'https://graph.facebook.com/'.$post['object_id'].'/picture';
}else if (isset($post['full_picture'])) {
$image_url = $post['full_picture'];
}else{
$image_url = '';
}
試過這個,但是...不幸的是full_picture鏈接指向一個相當小的圖像:( – 2015-02-03 20:51:24
您的權利@YoupTube經過一些更多的實驗後,我需要更新我的答案... – 2015-02-04 10:39:11
從另一篇文章中我學會了使用「附件」。那個人正在爲我工作。它包含一個帶有圖像和來源的媒體節點。自己試試! – 2015-02-04 10:40:29
從@Lachezar託多羅夫我決定後我目前的做法正面評論後(包括尋呼並使用Json.NET;):
try
{
FacebookClient fbClient = new FacebookClient(HttpContext.Current.Session[SessionFacebookAccessToken].ToString());
JObject posts = JObject.Parse(fbClient.Get(String.Format("/{0}/posts?fields=message,picture,link,attachments", FacebookPageId)).ToString());
JArray newsItems = (JArray)posts["data"];
List<NewsItem> result = new List<NewsItem>();
while (newsItems.Count > 0)
{
result.AddRange(GetItemsFromJsonData(newsItems));
if (result.Count > MaxNewsItems)
{
result.RemoveRange(MaxNewsItems, result.Count - MaxNewsItems);
break;
}
JToken paging = posts["paging"];
if (paging != null)
{
if (paging["next"] != null)
{
posts = JObject.Parse(fbClient.Get(paging.Value<String>("next")).ToString());
newsItems = (JArray)posts["data"];
}
}
}
return result;
}
和輔助方法retieve個別項目:
private static IEnumerable<NewsItem> GetItemsFromJsonData(IEnumerable<JToken> items)
{
List<NewsItem> newsItems = new List<NewsItem>();
foreach (JToken item in items.Where(item => item["message"] != null))
{
NewsItem ni = new NewsItem
{
Message = item.Value<String>("message"),
DateTimeCreation = item.Value<DateTime?>("created_time"),
Link = item.Value<String>("link"),
Thumbnail = item.Value<String>("picture"),
// http://stackoverflow.com/questions/28319242/simplify-looking-up-nested-json-values-with-json-net/28359155#28359155
Image = (String)item.SelectToken("attachments.data[0].media.image.src") ?? (String)item.SelectToken("attachments.data[0].subattachments.data[0].media.image.src")
};
newsItems.Add(ni);
}
return newsItems;
}
NewsItem類使用:
public class NewsItem
{
public String Message { get; set; }
public DateTime? DateTimeCreation { get; set; }
public String Link { get; set; }
public String Thumbnail { get; set; }
public String Image { get; set; }
}
參見: 「類型=大」 http://api-portal.anypoint.mulesoft.com/facebook/api/facebook-graph-api/docs/reference/pictures
只要把URL後獲得大的圖片。
我覺得這可能是這裏最可行的解決方案。值得注意的是/ me/picture?type = large會將302重定向到圖像本身。如果你想要實際的數據,包括圖像的URL,那麼你將需要傳遞?redirect = false參數。 – SpongeBobPHPPants 2015-09-17 15:31:09
- 1. 如何從Facebook中獲取大尺寸圖片圖形api
- 2. 使用Google Feed API獲取圖片
- 3. 如何使用Facebook圖形API獲取新聞Feed?
- 4. 使用圖形API獲取Facebook的圖片 - 比picture.type(大)
- 5. 如何使用Facebook PHP圖形API獲取用戶圖片?
- 6. Facebooker和圖形API,獲取新聞Feed
- 7. Zend_Feed:從Feed中獲取圖片URL
- 8. Facebook圖形API iOS:如何獲取Feed圖片的寬度和高度?
- 9. 從facebook圖形獲取完整大小的圖片API
- 10. eBay API - 如何獲取大型圖片?
- 11. Facebook圖形API獲取原始圖片大小不起作用
- 12. 從rss feed獲取圖片網址?
- 13. 如何獲取/使用圖形API
- 14. 通過圖形API發佈到FB feed時應使用什麼圖片大小?
- 15. 從rss feed提取圖片
- 16. 如何從facebook圖形API獲得100x100方形圖片?
- 17. 如何僅使用圖形API從用戶的Facebook新聞中獲取照片?
- 18. 如何從wordpress中的RSS feed獲取圖片?
- 19. 如何使用Facebook圖形API獲取專輯照片?
- 20. 如何從web api url獲取圖片?
- 21. 如何從wikipedia API獲取圖片?
- 22. 如何從flickr獲取圖片API
- 23. 如何從Zabbix獲取圖形值API
- 24. Facebook的圖形API - 批量獲取大型圖片
- 25. 從foursquare獲取圖片API
- 26. 如何使用jQuery從文件中獲取圖片大小?
- 27. 如何從discogs api獲取大圖像?
- 28. 使用圖形API獲取Facebook頁面圖片流
- 29. 用於沙盒模式下的Feed圖形API圖片
- 30. 圖形API:檢索頁面Feed中的圖片尺寸
當前的答案無效。請更新您選擇的答案。 @Benjamin Kuijten現在有正確的答案。 – 2015-02-18 08:55:48