本文整理汇总了PHP中Tweet::load_json_object方法的典型用法代码示例。如果您正苦于以下问题:PHP Tweet::load_json_object方法的具体用法?PHP Tweet::load_json_object怎么用?PHP Tweet::load_json_object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tweet
的用法示例。
在下文中一共展示了Tweet::load_json_object方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTweetsInJsonFile
/**
* Returns an array of Tweet objects that are populated from a Twitter JSON file.
*
* @return array|false
*/
public function getTweetsInJsonFile($filename)
{
$tweets = array();
if (!file_exists($filename) || file_exists($filename) && !is_readable($filename)) {
return false;
}
$jsonString = file_get_contents($filename);
if ($jsonString === false) {
return false;
}
// the twitter format includes extra JS code, but we just want the JSON array
$pattern = '/\\[.*\\]/s';
$matchError = preg_match($pattern, $jsonString, $matches);
// $matchError can be zero or false if not found or there was a failure
if (!$matchError) {
return false;
}
$jsonArrayString = $matches[0];
$jsonTweets = json_decode($jsonArrayString);
foreach ($jsonTweets as $tweet) {
$t = new Tweet();
$t->load_json_object($tweet);
$tweets[] = $t;
}
return $tweets;
}
示例2: testLoadJsonObject
public function testLoadJsonObject()
{
$user = new \stdClass();
$user->id = 14061545;
$tweetData = new \stdClass();
$tweetData->id = 293780221621067776;
$tweetData->user = $user;
$tweetData->created_at = '2013-01-22 13:00:37';
$tweetData->text = "Archive My Tweets has a new look, and can now import your official twitter archive. https://t.co/e8HDtbYa";
$tweetData->source = '<a href="http://twitterrific.com" rel="nofollow">Twitterrific for Mac</a>';
$tweetData->truncated = 0;
$tweetData->favorited = 0;
$tweetData->in_reply_to_status_id = 0;
$tweetData->in_reply_to_user_id = 0;
$tweetData->in_reply_to_screen_name = 0;
$t = new Tweet();
$t->load_json_object($tweetData);
foreach ($tweetData as $key => $value) {
if ($key == 'user' || $key == 'text') {
continue;
}
$this->assertEquals($tweetData->{$key}, $t->{$key});
}
$this->assertEquals($tweetData->user->id, $t->user_id);
$this->assertEquals($tweetData->text, $t->tweet);
}