|
|
تاریخ: جمعه 5 تیر 1394 - 16:09
|
imanmoodi
شروع فعاليت
پست: 16
عضو شده در: 13 مرداد 1390
محل سکونت: ايران
امتياز: 159
|
عنوان: پاسخ به «کمک از PHP کارها: لود توئیتهای سایت» |
|
|
کد: |
<?php
/**
* GetTweets - Used with Codebird-php to pull tweets from Twitter
* https://github.com/kevindeleon/get-tweets
*
* @author Kevin deLeon <https://github.com/kevindeleon/>
* @copyright 2013 Kevin deLeon <https://github.com/kevindeleon/>
*
* Licensed under the MIT license.
* https://github.com/kevindeleon/get-tweets/blob/master/LICENSE
*/
/**
* Class GetTweets
*/
mb_internal_encoding("UTF-8");
// Return hyperlinked tweet text from json_decoded status object:
class GetTweets {
/**
* Gets most recent tweets
* @param String twitter username (ex. kevindeleon)
* @param String number of tweets
* @param String include retweets true, false
* @return JSON encoded tweets
*/
static public function get_most_recent($screen_name, $count, $retweets = NULL)
{
//let's include codebird, as it's going to be doing the oauth lifting for us
require_once('includes/codebird/codebird.php');
//These are your keys/tokens/secrets provided by Twitter
$CONSUMER_KEY = 'XFWGJJvUu6j9CoUfoWEiHmyVp';
$CONSUMER_SECRET = 'aXGNVKvCIjgOexTJVmYuZoMBKNbDumsTVZe3W23kNsdrWyesW0';
$ACCESS_TOKEN = '7201482-RHTwumzq1C2YGwBNePAtBSoOKUhYmKWsfS8K6wK25H';
$ACCESS_TOKEN_SECRET = 'iq04w3N3C9WbJje0VqwvMrM3f344PIRoqV2OQikgv6z1a';
//Get authenticated
\Codebird\Codebird::setConsumerKey($CONSUMER_KEY, $CONSUMER_SECRET);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken($ACCESS_TOKEN, $ACCESS_TOKEN_SECRET);
//These are our params passed in
$params = array(
'screen_name' => $screen_name,
'count' => $count,
'include_rts' => $retweets,
);
//tweets returned by Twitter
$tweets = (array) $cb->statuses_userTimeline($params);
$tweets2=array();
foreach ($tweets as $twit) {
$tweets2[]=GetTweets::linkEntitiesWithinText($twit);
}
$i=0;
foreach ($tweets2 as $newTwit) {
$tweets[$i]->text='<img src="icon.png"> '.$newTwit;
$i++;
}
//Let's encode it for our JS/jQuery
return json_encode($tweets);
}
static public function mb_str_split($string,$string_length=1) {
if(mb_strlen($string) && $string_length || !$string_length) {
do {
$c = mb_strlen($string);
$parts[] = mb_substr($string,0,$string_length);
$string = mb_substr($string,$string_length);
}while(!empty($string));
} else {
$parts = array($string);
}
return $parts;
}
static public function linkEntitiesWithinText($apiResponseTweetObject) {
// Convert tweet text to array of one-character strings
$characters = GetTweets::mb_str_split($apiResponseTweetObject->text);
// Insert starting and closing link tags at indices...
// ... for @user_mentions
foreach ((object) $apiResponseTweetObject->entities->user_mentions as $entity) {
$link = "https://twitter.com/" . $entity->screen_name;
$characters[$entity->indices[0]] = "<a href=\"$link\">" . $characters[$entity->indices[0]];
$characters[$entity->indices[1] - 1] .= "</a>";
}
// ... for #hashtags
foreach ((object) $apiResponseTweetObject->entities->hashtags as $entity) {
$link = "https://twitter.com/search?q=%23" . $entity->text;
$characters[$entity->indices[0]] = "<a href=\"$link\">" . $characters[$entity->indices[0]];
$characters[$entity->indices[1] - 1] .= "</a>";
}
// ... for http://urls
foreach ((object) $apiResponseTweetObject->entities->urls as $entity) {
$link = $entity->expanded_url;
for ($i=$entity->indices[0]; $i < $entity->indices[1]; $i++) {
$characters[$i] = "";
}
$characters[$entity->indices[0]] = "$link";
}
// ... for media
foreach ((object) $apiResponseTweetObject->entities->media as $entity) {
$link = $entity->expanded_url;
$characters[$entity->indices[0]] = "<a href=\"$link\">" . $characters[$entity->indices[0]];
$characters[$entity->indices[1] - 1] .= "</a>";
}
// Convert array back to string
return implode('', $characters);
}
} |
http://aftab.vvs.ir |
|
[ وضعيت كاربر: ]
|
تشکرها از این پست:
|
|
|
صفحه 1 از 1
تمام زمانها بر حسب GMT + 3.5 Hours میباشند
|
|
شما نمی توانید در این بخش موضوع جدید پست کنید شما نمی توانید در این بخش به موضوعها پاسخ دهید شما نمی توانید موضوع های خودتان را در این بخش ویرایش کنید شما نمی توانید موضوع های خودتان را در این بخش حذف کنید شما نمی توانید در این بخش رای دهید
|
|
|