Comments (12)
See if this closed issue addresses your question. #29
Let me know if not.
from tweetledee.
It didnt work. Take a look at this code and tell me where i am wrong?
<?php
// include' OAuth library
require 'php/tmhOAuth.php';
require 'php/tmhUtilities.php';
// get the keys that allow connection to twitter
require 'keys/personal_keys.php';
/**------------------------------------------------------------------------------------------------*
* reformats the date retreived from Twitter to the format required for RSS *
* (quick and nasty method) *
*-------------------------------------------------------------------------------------------------*/
function reformatDate($s) {
$t = explode(' ', $s);
return $t[0] . ', ' . $t[2] . ' ' . $t[1] . ' ' . $t[5] . ' ' . $t[3] . ' ' . $t[4];
}
/*-------------------------------------------------------------------------------------------------*
* parses the tweet text turning links, users and hash tags into links *
*-------------------------------------------------------------------------------------------------*/
function parseTweet($s) {
return parseTags(parseNames(parseLinks($s)));
}
/*-------------------------------------------------------------------------------------------------*
* parses urls in the tweet text them into links *
*-------------------------------------------------------------------------------------------------*/
function parseLinks($s) {
return preg_replace_callback(
'#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', create_function(
'$matches', 'return "<a href=\'{$matches[0]}\'>{$matches[0]}</a>";'
), $s
);
}
/*-------------------------------------------------------------------------------------------------*
* parses @names in the tweet text turning them into links *
*-------------------------------------------------------------------------------------------------*/
function parseNames($s) {
return preg_replace('/@(\w+)/', '<a href="http://twitter.com/$1">@$1</a>', $s);
}
/*-------------------------------------------------------------------------------------------------*
* parses hash tags in the tweet text turning them into links *
*-------------------------------------------------------------------------------------------------*/
function parseTags($s) {
return preg_replace('/\s+#(\w+)/', ' <a href="http://search.twitter.com/search?q=%23$1">#$1</a>', $s);
}
function object_to_array(stdClass $Class){
# Typecast to (array) automatically converts stdClass -> array.
$Class = (array)$Class;
# Iterate through the former properties looking for any stdClass properties.
# Recursively apply (array).
foreach($Class as $key => $value){
if(is_object($value)&&get_class($value)==='stdClass'){
$Class[$key] = object_to_array($value);
}
}
return $Class;
}
function objectToArray($object)
{
if(!is_object( $object ) && !is_array( $object ))
{
return $object;
}
if(is_object($object) )
{
$object = get_object_vars( $object );
}
return array_map('objectToArray', $object );
}
// create the OAuth object
///*
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $my_consumer_key,
'consumer_secret' => $my_consumer_secret,
'user_token' => $my_access_token,
'user_secret' => $my_access_token_secret,
'curl_ssl_verifypeer' => false
));
//*/
// request the user information
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/account/verify_credentials'),
array(
'include_entities' => true,
'skip_status' => true,
)
);
// Anything except code 200 is a failure to get the information
if ($code <> 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("verify_credentials connection failure");
}
$userInfoObj = json_decode($tmhOAuth->response['response']);
//tmhUtilities::pr($userInfoObj);
// extract certain info about the user
$twitterName = $userInfoObj->screen_name;
$fullName = $userInfoObj->name;
$twitterAvatarUrl = $userInfoObj->profile_image_url;
$feedTitle = $twitterName . ' Twitter ' . $twitterName . 'Timeline';
// request the home time line - the last 50 item
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/statuses/mentions_timeline'),
array(
'include_entities' => true,
'count' => 50,
)
);
// Anything except code 200 is a failure to get the information
if ($code <> 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("home_timeline connection failure");
}
$homeTimelineObj = json_decode($tmhOAuth->response['response']);
// Start the output
header("Content-Type: application/rss+xml");
header("Content-type: text/xml; charset=utf-8");
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="<?= $my_domain ?><?= $_SERVER['PHP_SELF'] ?>" rel="self" type="application/rss+xml" />
<lastBuildDate><?= date(DATE_RSS); ?></lastBuildDate>
<language>en-gb</language>
<title><?= $feedTitle; ?></title>
<description>
RSS Twitter updates for <?= $fullName; ?> / <?= $twitterName; ?>.
</description>
<link>http://www.twitter.com/<?= $twitterName; ?></link>
<ttl>960</ttl>
<generator>Custom PHP</generator>
<category>Personal</category>
<image>
<title><?= $feedTitle; ?></title>
<link>http://www.twitter.com/<?= $twitterName; ?></link>
<url><?= $twitterAvatarUrl ?></url>
</image>
<?php foreach ($homeTimelineObj as $currentitem) : ?>
<item>
<?php
$parsedTweet = tmhUtilities::entify_with_options(
objectToArray($currentitem),
array(
'target' => 'blank',
)
);
if (isset($currentitem->retweeted_status)) :
$avatar = $currentitem->retweeted_status->user->profile_image_url;
$rt = ' [<em style="font-size:smaller;">Retweed by ' . $currentitem->user->name . ' <a href=\'http://twitter.com/' . $currentitem->user->screen_name . '\'>@' . $currentitem->user->screen_name . '</a></em>]';
$tweeter = $currentitem->retweeted_status->user->screen_name;
$fullname = $currentitem->retweeted_status->user->name;
$tweetTitle = $currentitem->retweeted_status->text;
else :
$avatar = $currentitem->user->profile_image_url;
$rt = '';
$tweeter = $currentitem->user->screen_name;
$fullname = $currentitem->user->name;
$tweetTitle = $currentitem->text;
$imgurl = '';
if(isset($currentitem['entities']['media'][0]['media_url'])):
$picurl = $currentitem['entities']['media'][0]['media_url'];
endif;
endif;
?> <tweeter> @<?= $tweeter; ?> </tweeter>
<tweet> <?= $tweetTitle; ?> </tweet>
<pubDate><?= reformatDate($currentitem->created_at); ?></pubDate>
<link>https://twitter.com/<?= $twitterName ?>/statuses/<?= $currentitem->id_str; ?></link>
<guid isPermaLink='false'><?= $currentitem->id_str; ?></guid>
<description>
<![CDATA[
<div style='float:left;margin: 0 6px 6px 0;'>
<a href='https://twitter.com/<?= $twitterName ?>/statuses/<?= $currentitem->id_str; ?>' border=0 target='blank'>
<img src='<?= $avatar; ?>' border=0 /> </a>
</div>
<strong><?= $fullname; ?></strong> <a href='https://twitter.com/<?= $tweeter; ?>' target='blank'>@<?= $tweeter;?></a><?= $rt ?><br />
<?= $parsedTweet; ?>
]]>
</description>
<media:group>
<media:content url="<?php echo $picurl; ?>" type="image/jpeg" />
<media:title><?php echo $tweetTitle; ?></media:title>
<media:description><?php echo $tweetTitle; ?></media:description>
</media:group>
</item>
<?php endforeach; ?>
</channel>
</rss>
from tweetledee.
I need more detailed information about what you are trying to do and what changes you made to the above code.
from tweetledee.
The original script gets my mentions which is @Dj_Klint but i wanted it to also fetch photos posted on tweets am mentioned i can't seem to get it to work. I have tried everything i have researched but it gets errors. Here is the original script:
<?php
// include Use Matt Harris' OAuth library
require 'php/tmhOAuth.php';
require 'php/tmhUtilities.php';
// get the keys that allow connection to twitter
require 'keys/personal_keys.php';
/**------------------------------------------------------------------------------------------------*
* reformats the date retreived from Twitter to the format required for RSS *
* (quick and nasty method) *
*-------------------------------------------------------------------------------------------------*/
function reformatDate($s) {
$t = explode(' ', $s);
return $t[0] . ', ' . $t[2] . ' ' . $t[1] . ' ' . $t[5] . ' ' . $t[3] . ' ' . $t[4];
}
/*-------------------------------------------------------------------------------------------------*
* parses the tweet text turning links, users and hash tags into links *
*-------------------------------------------------------------------------------------------------*/
function parseTweet($s) {
return parseTags(parseNames(parseLinks($s)));
}
/*-------------------------------------------------------------------------------------------------*
* parses urls in the tweet text them into links *
*-------------------------------------------------------------------------------------------------*/
function parseLinks($s) {
return preg_replace_callback(
'#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', create_function(
'$matches', 'return "<a href=\'{$matches[0]}\'>{$matches[0]}</a>";'
), $s
);
}
/*-------------------------------------------------------------------------------------------------*
* parses @names in the tweet text turning them into links *
*-------------------------------------------------------------------------------------------------*/
function parseNames($s) {
return preg_replace('/@(\w+)/', '<a href="http://twitter.com/$1">@$1</a>', $s);
}
/*-------------------------------------------------------------------------------------------------*
* parses hash tags in the tweet text turning them into links *
*-------------------------------------------------------------------------------------------------*/
function parseTags($s) {
return preg_replace('/\s+#(\w+)/', ' <a href="http://search.twitter.com/search?q=%23$1">#$1</a>', $s);
}
function object_to_array(stdClass $Class){
# Typecast to (array) automatically converts stdClass -> array.
$Class = (array)$Class;
# Iterate through the former properties looking for any stdClass properties.
# Recursively apply (array).
foreach($Class as $key => $value){
if(is_object($value)&&get_class($value)==='stdClass'){
$Class[$key] = object_to_array($value);
}
}
return $Class;
}
function objectToArray($object)
{
if(!is_object( $object ) && !is_array( $object ))
{
return $object;
}
if(is_object($object) )
{
$object = get_object_vars( $object );
}
return array_map('objectToArray', $object );
}
// create the OAuth object
///*
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $my_consumer_key,
'consumer_secret' => $my_consumer_secret,
'user_token' => $my_access_token,
'user_secret' => $my_access_token_secret,
'curl_ssl_verifypeer' => false
));
//*/
// request the user information
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/account/verify_credentials'),
array(
'include_entities' => true,
'skip_status' => true,
)
);
// Anything except code 200 is a failure to get the information
if ($code <> 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("verify_credentials connection failure");
}
$userInfoObj = json_decode($tmhOAuth->response['response']);
//tmhUtilities::pr($userInfoObj);
// extract certain info about the user
$twitterName = $userInfoObj->screen_name;
$fullName = $userInfoObj->name;
$twitterAvatarUrl = $userInfoObj->profile_image_url;
$feedTitle = $twitterName . ' Twitter ' . $twitterName . 'Timeline';
// request the home time line - the last 50 item
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/statuses/mentions_timeline'),
array(
'include_entities' => true,
'count' => 50,
)
);
// Anything except code 200 is a failure to get the information
if ($code <> 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("home_timeline connection failure");
}
$homeTimelineObj = json_decode($tmhOAuth->response['response']);
// Start the output
header("Content-Type: application/rss+xml");
header("Content-type: text/xml; charset=utf-8");
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="<?= $my_domain ?><?= $_SERVER['PHP_SELF'] ?>" rel="self" type="application/rss+xml" />
<lastBuildDate><?= date(DATE_RSS); ?></lastBuildDate>
<language>en-gb</language>
<title><?= $feedTitle; ?></title>
<description>
RSS Twitter updates for <?= $fullName; ?> / <?= $twitterName; ?>.
</description>
<link>http://www.twitter.com/<?= $twitterName; ?></link>
<ttl>960</ttl>
<generator>Custom PHP</generator>
<category>Personal</category>
<image>
<title><?= $feedTitle; ?></title>
<link>http://www.twitter.com/<?= $twitterName; ?></link>
<url><?= $twitterAvatarUrl ?></url>
</image>
<?php foreach ($homeTimelineObj as $currentitem) : ?>
<item>
<?php
$parsedTweet = tmhUtilities::entify_with_options(
objectToArray($currentitem),
array(
'target' => 'blank',
)
);
if (isset($currentitem->retweeted_status)) :
$avatar = $currentitem->retweeted_status->user->profile_image_url;
$rt = ' [<em style="font-size:smaller;">Retweed by ' . $currentitem->user->name . ' <a href=\'http://twitter.com/' . $currentitem->user->screen_name . '\'>@' . $currentitem->user->screen_name . '</a></em>]';
$tweeter = $currentitem->retweeted_status->user->screen_name;
$fullname = $currentitem->retweeted_status->user->name;
$tweetTitle = $currentitem->retweeted_status->text;
else :
$avatar = $currentitem->user->profile_image_url;
$rt = '';
$tweeter = $currentitem->user->screen_name;
$fullname = $currentitem->user->name;
$tweetTitle = $currentitem->text;
endif;
?> <tweeter> @<?= $tweeter; ?> </tweeter>
<tweet> <?= $tweetTitle; ?> </tweet>
<pubDate><?= reformatDate($currentitem->created_at); ?></pubDate>
<link>https://twitter.com/<?= $twitterName ?>/statuses/<?= $currentitem->id_str; ?></link>
<guid isPermaLink='false'><?= $currentitem->id_str; ?></guid>
<description>
<![CDATA[
<div style='float:left;margin: 0 6px 6px 0;'>
<a href='https://twitter.com/<?= $twitterName ?>/statuses/<?= $currentitem->id_str; ?>' border=0 target='blank'>
</div>
<strong><?= $fullname; ?></strong> <a href='https://twitter.com/<?= $tweeter; ?>' target='blank'>@<?= $tweeter;?></a><?= $rt ?><br />
<?= $parsedTweet; ?>
]]>
</description>
</item>
<?php endforeach; ?>
</channel>
</rss>
from tweetledee.
Where did i go wrong?
from tweetledee.
Hey, i got it to work but it is returning pics that are not for the tweets.
from tweetledee.
What do you mean by "tweets am mentioned"? Do you mean you want photos from other accounts that mention your Twitter handle?
from tweetledee.
yes. and also to get rid of the "http://" after a tweet or in between a tweet
from tweetledee.
I managed to get photos on tweets with pics but the problem is the tweet comes with something like this:
Have you heard this song? Mr Phat-Mama http://t.co/APywhtwIdV via @kymdynis @Dj_Klint.
how can i get rid of this 'http://t.co/APywhtwldV'
from tweetledee.
It doesn't look like there is a straightforward fix with the PHP variables that are generated from the Twitter API data.
If the link is part of the tweet text, you would need to parse every tweet string with PHP and then replace all identified URL's with an empty string. This is likely a job best done with regular expressions.
PHP documentation on preg_replace
that would allow you to match a URL and replace it with an empty string to remove it:
http://php.net/manual/en/function.preg-replace.php
And here is a Stack Overflow article on regular expressions for URL:
The tweet text is stored in the $tweetTitle
PHP variable in the above script that you linked.
from tweetledee.
Thank You Chris. Thanks alot.
from tweetledee.
were you able to come up with a solution?
from tweetledee.
Related Issues (20)
- 280 characters HOT 2
- media content privileged over profile images? HOT 1
- hashtag entity replacements generating error HOT 1
- Show all images of tweet HOT 3
- Quoting another tweet should have the other tweet included in feed HOT 10
- Fight duplication ! HOT 4
- Add a comparison with RSS-Bridge HOT 4
- Factorize parameters processing
- Factorize debug flag management
- Set author in RSS entry according to twitter handle
- "user_timeline connection failure" when I use searchrss.php HOT 4
- The *_nocache embarks a bug HOT 1
- This tweet breaks tweetledee HOT 2
- Use https for avatar img src? HOT 2
- Undefined index: type in parametersProcessing.php HOT 2
- Latest redesign of Twitter makes retweets impossible to open HOT 1
- No images are shown HOT 1
- User with a username that end with underscore not work properly HOT 4
- Tweet breaks LibXML
- Tweetledee is broken HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tweetledee.