本文整理汇总了PHP中Tweet::loadFromJsonObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Tweet::loadFromJsonObject方法的具体用法?PHP Tweet::loadFromJsonObject怎么用?PHP Tweet::loadFromJsonObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tweet
的用法示例。
在下文中一共展示了Tweet::loadFromJsonObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTweetsInJsonFile
/**
* Returns an array of Tweet objects that are populated from a Twitter JSON file.
*
* @param string $filename
* @return array|false
*/
public function getTweetsInJsonFile($filename)
{
$tweets = [];
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->loadFromJsonObject($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->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->loadFromJsonObject($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);
}