새로운 트위터 API로 CakePHP 요소의 트위터 페이지에서 5 개의 트윗을 어떻게 표시 할 수 있습니까? 플러그인이 있습니까? 죄송합니다.이 바보 같은 질문이 있지만 전에 트위터 API와 함께 일한 적이 있습니다.Cakephp 디스플레이 짹짹
1
A
답변
1
0
나는 새로운 API와 함께 작동하는 CakePHP의 플러그인을 인식 아니지만, 작업 꽤 쉽게 멋진 일반 PHP 라이브러리가 - 당신은 트위터에서 응용 프로그램을 만들 필요가 https://github.com/jublonet/codebird-php
는에, 귀하의 소비자 키와 토큰을 받으십시오.
app/Config/bootstrap.php
에서
Cache::config('three_hour_config', array(
'engine' => 'File', //[required]
'duration'=> '+3 hours', //[optional]
'probability'=> 100, //[optional]
'mask' => 0777, // [optional] permission mask to use when creating cache files
));
(당신이 그 (것)들에게 모든 요청을하지, 트윗을 캐시 할 수 있습니다) : CakePHP의 얼마 전에 앱
여기에 내가 작업 얻을하는 데 사용되는 코드의 몇 가지 관련 조각의 컨트롤러에서
- 어쩌면 AppController.php
: 다음
private function __setLatestTweets() {
$rawTweets = Cache::read('rawTweets', 'three_hour_config');
if (empty($rawTweets)) {
// from https://github.com/jublonet/codebird-php
require_once (APP . 'Vendor' . DS . 'jublonet' . DS . 'codebird-php' . DS . 'src' . DS . 'codebird.php');
\Codebird\Codebird::setConsumerKey('********', '*********');
$cb = \Codebird\Codebird::getInstance();
$cb->setToken('*****-**********', '*********');
$rawTweets = (array)$cb->statuses_userTimeline(array('count' => 1));
// remove the last key, which is not numeric.
// If we don't remove it, it's treated like a normal tweet and creates errors
unset($rawTweets['httpstatus']);
Cache::write('rawTweets', $rawTweets, 'three_hours');
}
$this->set('rawTweets',$rawTweets);
}
그리고 저를 포맷하는 데 도움이 도우미를 썼다 : /app/View/Helper/TwitterHelper.php
<?php
/* /app/View/Helper/TwitterHelper.php */
App::uses('AppHelper', 'View/Helper');
class TwitterHelper extends AppHelper {
public $helpers = array('Time');
public function formatTweets($tweets) {
$latestTweets = '';
foreach ($tweets as $tweet) {
if ($tweet->retweeted) {
$tweetText = $tweet->retweeted_status->text;
} else {
$tweetText = $tweet->text;
}
// Convert twitter Usernames and links to Hyperlinks
$tweetcontent = '<div class="tweet_content">' . $this->linkify($tweetText) . '</div>';
$tweetDate = strtotime($tweet->created_at);
$singleTweet = $tweetcontent . '<div class="tweet_footer">' .
$this->Time->timeAgoInWords($tweetDate) .
' ⋅ ' .
'<a href="https://twitter.com/intent/tweet?in_reply_to=' . number_format($tweet->id, 0, '', '') . '" class="twtr_reply" target="_blank">reply</a>' .
' ⋅ ' .
'<a href="https://twitter.com/intent/retweet?tweet_id=' . number_format($tweet->id, 0, '', '') . '" class="twtr-rt" target="_blank">retweet</a>' .
' ⋅ ' .
'<a href="https://twitter.com/intent/favorite?tweet_id=' . number_format($tweet->id, 0, '', '') . '" class="twtr-fav" target="_blank">favorite</a>' .
'</div>';
$latestTweets .= "<div class=\"single_tweet\"> $singleTweet </div>";
}
return $latestTweets;
}
/**
* Credit Jeremy Parrish http://rrish.org/
*/
public function linkify($statusText) {
// linkify URLs
$statusText = preg_replace(
'/(https?:\/\/\S+)/',
'<a target="_blank" href="\1">\1</a>',
$statusText
);
// linkify twitter users
$statusText = preg_replace(
'/(^|\s)@(\w+)/',
'\[email protected]<a target="_blank" href="http://twitter.com/\2">\2</a>',
$statusText
);
// linkify tags
$statusText = preg_replace(
'/(^|\s)#(\w+)/',
'\1#<a target="_blank" href="http://search.twitter.com/search?q=%23\2">\2</a>',
$statusText
);
return $statusText;
}
}
그리고보기에 당신은 같은 거라고 : 나는 당신이 관심이 있다면 쉽게이 작업을 수행 플러그인을 만들었습니다
<h4>Latest from Twitter</h4>
<div class="tweets_container">
<?php echo $this->Twitter->formatTweets($rawTweets); ?>
</div>
관련 문제
- 1. 짹짹 짹짹 짹짹 JSON nodejs와 SQL 테이블에
- 2. 트위터에서 짹짹 짹짹?
- 3. CakePHP 2.5 HttpSocket 디스플레이 응답
- 4. iOS 6의 특정 계정에서 짹짹 짹짹?
- 5. CakePHP 디스플레이 아약스를 사용하여 데이터 테이블을 업데이트
- 6. CakePHP 모델의 디스플레이 필드로 CONCAT() + JOIN을 사용합니다.
- 7. CakePHP 뷰에서 디스플레이 로직을 배치하는 모범 사례
- 8. 짹짹 분류
- 9. 트위터 : 짹짹
- 10. 짹짹 정확한 위치
- 11. 문제 PHP로 짹짹 캐쉬하기
- 12. 짹짹 좋아하는 카운트
- 13. Twitterizer를 사용하여 짹짹 올리기
- 14. 가로 스크롤 짹짹
- 15. 단축 텍스트는 짹짹 같은
- 16. 트위터 API 위치 짹짹
- 17. PHP 트윗 짹짹 Langauge
- 18. 안드로이드를 통해 짹짹 읽기
- 19. 탐색 모음의 짹짹 버튼
- 20. 재능있는 친구 초당 짹짹
- 21. HackerRank 짹짹 우려
- 22. 짹짹 위상 변경
- 23. 짹짹 검색을위한 Java 라이브러리
- 24. 토큰을 사용하여 짹짹 올리기
- 25. Twitter 짹짹 등을 분석
- 26. Spotify 앱에 짹짹 달기
- 27. 짹짹 모음을 찾으려면 어떻게해야합니까?
- 28. 짹 짹짹 짹짹에만
- 29. 짹짹 여러 사진 안드로이드
- 30. 자바 코드 검색 짹짹