Skip to content

Instantly share code, notes, and snippets.

@bueckl
Created December 11, 2015 10:33
Show Gist options
  • Save bueckl/d1b4418e3873c4830645 to your computer and use it in GitHub Desktop.
Save bueckl/d1b4418e3873c4830645 to your computer and use it in GitHub Desktop.
#Silverstripe Convert JSON Data to ArrayData for Template
//http://stackoverflow.com/questions/19888110/silverstripe-convert-twitter-json-string-to-dataobject-to-loop-though-in-templa
public static function getTwitterFeed(){
$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?screen_name=xxx&count=5';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$returnTwitter = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
$returnTwitter = Convert::json2array($returnTwitter);
$tweets = array();
foreach ($returnTwitter as $key => $value) {
$tweets[] = new ArrayData(array('created_at' => $value['created_at'], 'text' => $value['text']));
}
return new ArrayList($tweets);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment