Extract images with a certain tag from Instagram

MultiformeIngegno

  • Posts: 1,337
Re: Extract images with a certain tag from Instagram
« Reply #15, on April 20th, 2012, 02:00 AM »
Quote from Nao on April 19th, 2012, 06:18 PM
How come I never heard about Amstamgram before they got gobbled up by Facebook? :P
Eh eh! I knew it already.. anyway this acquisition made it of course more and more famous. ;)

Okay.. now that I managed to get it working I.. have another question. :P
I'm using this code to create a list of tweets from my Twitter account:
Code: [Select]
<?php
$json wp_remote_get("http://twitter.com/status/user_timeline/lorenzoraffio.json?count=6"true);
$decode json_decode($json['body'], true);
echo "
<ul style='color:#6E6E6E'>"
;
$count count($decode); //counting the number of status
$date $tweets['created_at']; // created date
for($i=0;$i<$count;$i++){ echo '
<li>'
.$decode[$i]['text'].'<br><a href='; echo '"http://twitter.com/#!/'.$decode[0][user][name].'/status/'.$decode[$i][id].'"><small>'date('j F',strtotime($decode[$i]['created_at'])) ."</small></a> - <a href='http://twitter.com/intent/tweet?in_reply_to=".$decode[$i][id]."'><small>rispondi</small></a> - <a href='http://twitter.com/intent/retweet?tweet_id=".$decode[$i][id]."'><small>retweet</small></a> - <a href='http://twitter.com/intent/favorite?tweet_id=".$decode[$i][id]."'><small>preferito</small></a></li>";} echo "
</ul>
"
;
?>


Everything works perfectly except that the dates are in english. I need to set italian language for the strtotime function.. I know I need to use setlocale(LC_TIME, 'it_IT'); but I don't know where to add it..

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

MultiformeIngegno

  • Posts: 1,337
Re: Extract images with a certain tag from Instagram
« Reply #17, on April 20th, 2012, 02:14 AM »
Uhm.. dates are still in english..
Code: [Select]
<?php
setlocale(LC_TIME'it_IT');
$json wp_remote_get("http://twitter.com/status/user_timeline/lorenzoraffio.json?count=6"true);
$decode json_decode($json['body'], true);
echo "
<ul style='color:#6E6E6E'>"
;
$count count($decode); //counting the number of status
$date $tweets['created_at']; // created date
for($i=0;$i<$count;$i++){ echo '
<li>'
.$decode[$i]['text'].'<br><a href='; echo '"http://twitter.com/#!/'.$decode[0][user][name].'/status/'.$decode[$i][id].'"><small>'date('j F',strtotime($decode[$i]['created_at'])) ."</small></a> - <a href='http://twitter.com/intent/tweet?in_reply_to=".$decode[$i][id]."'><small>rispondi</small></a> - <a href='http://twitter.com/intent/retweet?tweet_id=".$decode[$i][id]."'><small>retweet</small></a> - <a href='http://twitter.com/intent/favorite?tweet_id=".$decode[$i][id]."'><small>preferito</small></a></li>";} echo "
</ul>
"
;
?>


And another question.. would it be faster (and better) to use file_get_contents or wp_remote_get (a WP function that uses the HTTP GET method..)? :)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

MultiformeIngegno

  • Posts: 1,337
Re: Extract images with a certain tag from Instagram
« Reply #19, on April 20th, 2012, 02:34 AM »
Code: [Select]
<?php
setlocale(LC_TIME'it_IT');
$json wp_remote_get("http://twitter.com/status/user_timeline/lorenzoraffio.json?count=6"true);
$decode json_decode($json['body'], true);
echo "
<ul style='color:#6E6E6E'>"
;
$count count($decode); //counting the number of status
$date $tweets['created_at']; // created date
for($i=0;$i<$count;$i++){ echo '
<li>'
.$decode[$i]['text'].'<br><a href='; echo '"http://twitter.com/#!/'.$decode[0][user][name].'/status/'.$decode[$i][id].'"><small>'date('j F',strftime($decode[$i]['created_at'])) ."</small></a> - <a href='http://twitter.com/intent/tweet?in_reply_to=".$decode[$i][id]."'><small>rispondi</small></a> - <a href='http://twitter.com/intent/retweet?tweet_id=".$decode[$i][id]."'><small>retweet</small></a> - <a href='http://twitter.com/intent/favorite?tweet_id=".$decode[$i][id]."'><small>preferito</small></a></li>";} echo "
</ul>
"
;
?>


Warning: date() expects parameter 2 to be long :blush:
I'm doing it wrong.. right? :P

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Extract images with a certain tag from Instagram
« Reply #20, on April 20th, 2012, 02:42 AM »
Yes, you're doing it wrong. Don't use date, as I said, it doesn't do what you want. And plugging in strftime has broken it because date wants a number, not a string, hence the error.

Code: [Select]
strftime('%e %B',strtotime($decode[$i]['created_at']))

It won't work on Windows, though as %e isn't supported.

MultiformeIngegno

  • Posts: 1,337
Re: Extract images with a certain tag from Instagram
« Reply #21, on April 20th, 2012, 02:48 AM »
Oh! Clear now. :)
Am I wrong or the line $date = $tweets['created_at']; is useless (because then I decode the date directly from the JSON)..? It confused me a bit... I thought I needed to change that too but then I realized I don't need that... Right?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

MultiformeIngegno

  • Posts: 1,337

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Extract images with a certain tag from Instagram
« Reply #24, on April 20th, 2012, 02:58 AM »
Considering that I have no idea what wp_remote_get does (and note that file_get_contents with the URL wrapper does also use the HTTP GET method), I cannot answer that question, and no, I'm not about to trawl through the shit-heap that is WP's source to find out.

What I can tell you is that if file_get_contents works, it's certainly workable. But it has limitations, namely that it's not particularly flexible across servers since it's easy to disable it at the config level, and it isn't robust in terms of handling time-outs. If WP's function handles *any* of that (and even my lack of faith in WP's code suggests that it would handle *some* of it), run with it.

If this were file_get_contents vs Wedge's equivalent (the weget class), I'd have no hesitation in recommending Wedge's own much lengthier and likely slower - but far far more robust solution. I would likely argue the same for WP's case.

MultiformeIngegno

  • Posts: 1,337
Re: Extract images with a certain tag from Instagram
« Reply #25, on April 20th, 2012, 02:20 PM »
Reasonable. :)

I "applied" htmlentities to my decoded data: '.htmlentities($value->caption->text).'
The downside is that accents are broken, example:  ì becomes Ã~

Page char-set is UTF-8. I thought it would have handled accented chars properly...!

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

MultiformeIngegno

  • Posts: 1,337

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

PantsManUK

  • [me=PantsManUK]would dearly love to dump SMF 1.X at this juncture...[/me]
  • Posts: 174
« What is this thing you hoomans call "Facebook"? »