HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Twitter Feed Integration Block discussion

Login / Search

 [ Join | More ]
 Add topic 
Posted
Item has a rating of 5 (Liked by Chris GrahamLiked by Robbie GoacherLiked by Jean)  
Rating:
#92759 (In Topic #18589)
Avatar

Community saint

Greetings everybody!

The addon is now available in the Addons->Version 9.0->3rd Party Integration downloads section: Twitter Feed Integration Block (The addon is also committed to the v9 branch of the ocPortal github repository)

I've started this topic for the Twitter Feed Integration Block addon to report bugs, to suggest additions and improvements, and to provide some documentation for the templates. If you use the addon and find any bugs, please report them here or in the comments for the addon in the Addons page. Same goes for suggestions.

The list of bugs and improvements:
  • None at this time.

Documentation:

Some quick notes...The block is listed in the Version 9.0 addons download section. If you are using ocPortal 9.x.x, you can download and install the addon from your web site Admin Zone->Structure->Addons area. If you are using ocPortal 8.x.x, you can download the version 9.0 addon and manually upload and install it from your web site Admin Zone->Structure->Addons area. This addon hasn't been tested on any version prior to ocPortal v9.0.2, but should be functional backwards to any version that supports the Twitter Support addon. The times passed to the templates are UTC. ocPortal v9.0.2 and earlier will display tweet times in UTC time for everyone. An update for sources\symbols.php is in the github repository and the next ocPortal release should show tweet times as UTC time for guests and show the timezone adjusted times for the configured timezone for logged in members. This addon requires the Twitter Support addon to be installed. By default, this block uses the same Twitter API key and secret code as the Twitter Support addon if they have been configured. You will find the option to disable this in the Admin Zone -> Setup -> Configuration -> Block options. There you will find a Twitter Feed Integration Block section with two options...a 'Use Twitter Support API Key and Secret' and 'Time between updates'. If checked, the 'Use Twitter Support API Key and Secret' allows you to use the Twitter Support API key and secret as the default. If not checked, the Twitter API key and secret must be supplied as a block parameters. The 'Time between updates' option specifies the time (in minutes) between updates. The default is 30 minutes. You may need shorter update time if you are monitoring a very active twitter feed. If there will be a limited number of your web site members allowed or able to use this block and you have the Twitter Support API key and secret already configured, you can check the 'Use Twitter Support API Key and Secret' option for simplicity. If you check this option and the Twitter Support API key and secret are not configured, you will need to supply the key and secret as parameters for the block. If you will be setting up this block to monitor several Twitter feeds or allow several users access to this block, it would be best to uncheck this option since you may excede the maximum allowed requests by the Twitter API.

The addon comes with a default set of template files. The style template is used to build the individual Tweets, and the main template that acts as a container for all of the Tweets. I have done my best to build three different styles that conform to the Twitter guidelines for displaying Tweets on 3rd party web sites. If you want to stylize and integrate your Tweets in other ways, you can create your own custom templates. To do this, you shouldn't modify the existing templates or they may be overwritten when updating the addon. Instead, you will create a new template with a specific name in the template_custom directory. Start with the original template name and append an underscore and your custom name to it. If the original template name is BLOCK_TWITTER_FEED_STYLE.tpl, you would copy or create a new file named something like BLOCK_TWITTER_FEED_STYLE_mytwitterstyle.tpl. Keep the original part of the file name in CAPS and add the underscore and custom name. Then alter this new template or clear it and start fresh. To use your new _mytwittersyle template, in the block parameters, set the Template Style parameter to mytwitterstyle (or whatever custom name you append to the original file name). Not tested, but I'm pretty sure case matters. If you used lower case for your appended custom name, then use lower case for the Template Style parameter. If you appended something like _MyTwitterStyle, then you would use MyTwitterStyle as the Template Style parameter. The Style block parameter can be used as you wish in your custom templates. I used numbers 1, 2, and 3 to define three different layouts in the default provided template, but you can change it to use text to define various layouts in a single custom template. If you're not too familiar with template logic code, you can ignore the Style parameter that is used by template logic code to control what html parts are visible. Instead, you can create as many custom templates as you want, each with a different layout.

Here is the documentation for what {VARIABLES} are used in the Style template. Each valid {VARIABLE} used in any Style templates will be replaced with the data specified in the documentation below:
  • {STYLE} = This is set with the Style block parameter. The default provided template takes 1, 2, or 3 as values to choose a layout style for tweets. 1 = Twitter-like clone, with user profile details. 2 = Full tweets, no user profile details. 3 = Compact but expandable tweets, no user profile details. You can use logic template code in your custom templates and use this variable to select your own layouts. For custom templates, you don't have to use numbers, you can use also use text.
  • {TWEET_TEXT} = Contains the tweet text.
  • {TWEET_ID} = Contains the tweet ID. May be needed if you create custom templates that need the tweet ID for certain Twitter URLs.
  • {TWEET_CREATED_AT} = Contains the date the tweet was created. Contains string in format: Sun Jan 01 01:00:25 +0000 2012. This is a UTC time. The default templates use tempcode to convert this to a timestamp and then back to a time string which adjusts the time to the timezone of the logged on user.
  • {TWEET_TIME_AGO} = Contains a string stating how long ago the tweet was created.
  • {TWEET_RETWEET_COUNT} = Contains the number of times the tweet was retweeted.
  • {TWEET_FAVORITED} = Contains true if the tweet has been favorited, false if the tweet has not been favorited. The favorite count is currently not available through the Twitter API.
  • {TWEET_RETWEETED} = Contains true if the tweet has been retweeted, false if the tweet has not been retweeted.
  • {REPLY_URL} = Contains the URL to reply to a tweet.
  • {RETWEET_URL} = Contains the URL to retweet a tweet.
  • {FAVORITE_URL} = Contains the URL to favorite a tweet.
  • {FOLLOW_BUTTON_SIZE} = Sets the follow button size. 1 = Normal follow button size. 2 = Large follow button size.
  • {FOLLOW_BUTTON_NORMAL} = Contains the entire normal size button and URL (contains entire code). Works in conjuction with java script embedded in main template (BLOCK_TWITTER_FEED.tpl).
  • {FOLLOW_BUTTON_LARGE} = Contains the entire large size button and URL (contains entire code). Works in conjuction with java script embedded in main template (BLOCK_TWITTER_FEED.tpl).
  • {TWITTER_LOGO_IMG_CODE} = Contains the ocPortal image code for the Twitter logo. Used by the {$IMG} tempcode to generate the image URL in the template.
  • {SHOW_PROFILE_IMAGE} = Sets whether the profile image is displayed in templates. 1 = Display profile image. 0 = Do not display profile image.
  • {USER_NAME} = Part of the user profile details, contains the Twitter user name (real name).
  • {USER_SCREEN_NAME} = Part of the user profile details, contains the Twitter screen name (alias).
  • {USER_LOCATION} = Part of the user profile details, displays the Twitter user location.
  • {USER_URL} = Part of the user profile details, contains the Twitter user web site URL (not the Twitter profile URL).
  • {USER_PAGE_URL} = Part of the user profile details, contains the Twitter user profile page URL.
  • {USER_LOCATION} = Part of the user profile details, contains the Twitter user location.
  • {USER_DESCRIPTION} = Part of the user profile details, contains the Twitter user description text.
  • {USER_FOLLOWERS_COUNT} = Part of the user profile details, contains the number of followers for the Twitter user.
  • {USER_FOLLOWING_COUNT} = Part of the user profile details, contains the number of people the Twitter user is following.
  • {USER_CREATED_AT} = Part of the user profile details, contains the date Twitter user was created. Contains string in format: Sun Jan 01 01:00:25 +0000 2012. This is a UTC time. The default templates use tempcode to convert this to a timestamp and then back to a time string which adjusts the time to the timezone of the logged on user.
  • {USER_FAVOURITES_COUNT} = Part of the user profile details, contains the number of tweets the Twitter user has favorited.
  • {USER_STATUS_COUNT} = Part of the user profile details, contains the number of tweets the Twitter user has tweeted.
  • {USER_VERIFIED} = Not used in default templates. Part of the user profile details, contains true if Twitter user is verifed or false if Twitter user is not verified.
  • {USER_PROFILE_IMG_URL} = Part of the user profile details, contains the URL of the Twitter user profile image.

The main template is simply just a container to hold the style template. I was going to put a comcode box defined with the Title block parameter as the box title, but I opted to keep it out so you can create your own box to match the style of your site. Or you can create your own custom template and use {TWITTER_TITLE} for the box title.

Here is a list of {VARIABLES} available in the main BLOCK_TWITTER_FEED.tpl:
  • {TWITTER_ERROR} = This is set with a text error message. This is typically set to the error status set by the Twitter Class that does the Twitter API calls. The default templates will not display anything to guests or normal users when an error occurs. Only the site Staff will be able to see the error messages.
  • {TWITTER_TITLE} = Unused in the default template. You can set this with the Title block parameter and display it in your custom BLOCK_TWITTER_FEED.tpl template.
  • {CONTENT} = This is the list of tweets. All of the tweets are styled with the Style template and then combined into this single variable.
  • {STYLE} = This is set with the Style block parameter. The default provided template takes 1, 2, or 3 as values to choose a layout style for tweets. 1 = Twitter-like clone, with user profile details. 2 = Full tweets, no user profile details. 3 = Compact but expandable tweets, no user profile details. You can use logic template code in your custom templates and use this variable to select your own layouts. For custom templates, you don't have to use numbers, you can use also use text.
  • {TWITTER_LOGO_IMG_CODE} = Contains the ocPortal image code for the Twitter logo. Used by the {$IMG} tempcode to generate the image URL in the template.
  • {SHOW_PROFILE_IMAGE} = Sets whether the profile image is displayed in templates. 1 = Display profile image. 0 = Do not display profile image.
  • {FOLLOW_BUTTON_SIZE} = Sets the follow button size. 1 = Normal follow button size. 2 = Large follow button size.
  • {FOLLOW_BUTTON_NORMAL} = Contains the entire normal size button and URL (contains entire code). Works in conjuction with java script embedded in main template (BLOCK_TWITTER_FEED.tpl).
  • {FOLLOW_BUTTON_LARGE} = Contains the entire large size button and URL (contains entire code). Works in conjuction with java script embedded in main template (BLOCK_TWITTER_FEED.tpl).
  • {USER_NAME} = Part of the user profile details, contains the Twitter user name (real name).
  • {USER_SCREEN_NAME} = Part of the user profile details, contains the Twitter screen name (alias).
  • {USER_LOCATION} = Part of the user profile details, displays the Twitter user location.
  • {USER_URL} = Part of the user profile details, contains the Twitter user web site URL (not the Twitter profile URL).
  • {USER_PAGE_URL} = Part of the user profile details, contains the Twitter user profile page URL.
  • {USER_LOCATION} = Part of the user profile details, contains the Twitter user location.
  • {USER_DESCRIPTION} = Part of the user profile details, contains the Twitter user description text.
  • {USER_FOLLOWERS_COUNT} = Part of the user profile details, contains the number of followers for the Twitter user.
  • {USER_FOLLOWING_COUNT} = Part of the user profile details, contains the number of people the Twitter user is following.
  • {USER_CREATED_AT} = Part of the user profile details, contains the date Twitter user was created. Contains string in format: Sun Jan 01 01:00:25 +0000 2012. This is a UTC time. The default templates use tempcode to convert this to a timestamp and then back to a time string which adjusts the time to the timezone of the logged on user.
  • {USER_FAVOURITES_COUNT} = Part of the user profile details, contains the number of tweets the Twitter user has favorited.
  • {USER_STATUS_COUNT} = Part of the user profile details, contains the number of tweets the Twitter user has tweeted.
  • {USER_VERIFIED} = Not used in default templates. Part of the user profile details, contains true if Twitter user is verifed or false if Twitter user is not verified.
  • {USER_PROFILE_IMG_URL} = Part of the user profile details, contains the URL of the Twitter user profile image.

Here is a list of block parameters:
  • api_key = Unless the 'Use Twiter Support Config' block configuration option is enabled, you will need to supply your own API key and secret. You can get your key and secret by creating an application on Twitter (http://dev.twitter.com/apps/new). The 'Callback URL' field must be set to the web site base URL (for example: http://www.yourdomain.com). When you've saved, you'll need to change the 'Application type' setting to 'Read and Write'. You don't need to create an access token (ocPortal will negotiate this for you behind-the-scenes). Default: ''.
  • api_secret = This will also be provided after registering your application. Default: ''.
  • screen_name = The Twitter user screen name of the Twitter feed you want to embed. Default: 'coolweens'.
  • title = The title you want to give to your Twitter feed. (currently not used in the default templates) Default: ''.
  • template_main = If you create your own main template, you can enter the suffix name of your custom main template file. This is the main template where the style template will be added to. Example: if your custom template is named BLOCK_TWITTER_FEED_MyCustomTemplate.tpl, you would enter MyCustomTemplate here. When creating the template, be sure to use the original template file name and append an underscore and your custom name to it. I'm sure it's case sensitive as well. Default: ''.
  • template_style = If you create your own style template, you can enter the suffix name of your custom style template file. This is the style template where the actual Twitter provided data will be layed out. Check the 'Twitter Feed Integration Block discussion' topic on the ocPortal.com Forum for documentation of available template variables. Example: if your custom template is named BLOCK_TWITTER_FEED_STYLE_MyCustomStyle.tpl, you would enter MyCustomStyle here. When creating the template, be sure to use the original template file name and append an underscore and your custom name to it. I'm sure it's case sensitive as well. Default: ''.
  • max_statuses = You can specify the maximum number of status updates to show. Minimum value is 1, maximum value is 200 (max allowed by Twitter API). Default: '10'.
  • show_profile_image = Set this to 1 to show profile image. Set this to 0 to disable profile image. Default: '1'.
  • twitter_logo_color = This logo is shown in place of the Follow button if the Follow button is disabled per Twitter guidelines. Set this to select a Twitter logo color. 1 = Blue. 2 = Gray. 3 = Black. Default: '1'.
  • twitter_logo_size = Set this to select a Twitter logo size. 1 = 14x11 pixels. 2 = 32x25 pixels. 3 = 44x35 pixels. Default: '2'.
  • follow_button_size = Set this to 1 to show smaller (normal size) button. Set this to 2 to show a larger size button. Set this to 0 to disable the follow button. Default: '1'.
  • style = Set this to the style of output you want. If no style template is manually defined, style can be chosen by one of three styles: 1 = Twitter-like clone, with user profile details. 2 = Full tweets, no user profile details. 3 = Compact but expandable tweets, no user profile details. If you create a simple template, this can be ignored. If you create an advanced template, you can set this to a number or name that is referenced in your template file. Default: '1'.


Last edit: by Jason Verhagen
Back to the top
 
Posted
Rating:
#97584
Avatar

Community saint

I get the following error when trying to use the block:

Code

A parameter, IS_STAFF, is referenced in the template, BLOCK_TWITTER_FEED, but not passed

Any ideas?
Back to the top
 
Posted
Rating:
#97585
Avatar

Think in his BLOCK_TWITTER_FEED.tpl {IS_STAFF} should be {$IS_STAFF}.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#97586
Avatar

Community saint

Ok so in truth the real error is something to do with Screen name. I put in the Twitter username I have "PhpNukeClan" if I do I get a critical error

Code

PHP NOTICE [8] Undefined variable: user_page_url in sources_custom/blocks/twitter_feed.php on line 234 (version: 9.0.7, PHP version: 5.3.24, URL: /start.htm)

When setting up the API on dev.twitter I set application name as "PhpNukeClan CMS"

if I set screen name to that I don't get the critical error but I get the Staff parameter error so I removed the if staff from template and it prints the "PhpNukeClan CMS" name and below it an error "Not Authorized".

Back to the top
 
Posted
Rating:
#97587
Avatar

Community saint

That solved the IS Staff Problem Chris but I still can't use the proper Twitter Screen Name for some reason?
Back to the top
 
Posted
Rating:
#97588
Avatar

Community saint

Ok so I think I may have solved I was using Block settings (even though it was unchecked in admin config to use Twtter Sydication so I checked it and used that instaed but thos settings weren't initially showing up under features as expected.
Back to the top
 
Posted
Rating:
#97589
Avatar

Community saint

Nope I stand corrected I am still getting the critical error about user_page_url

However the APP is approved on my twitter profile now.
Back to the top
 
Posted
Rating:
#97590
Avatar

This addon is in git, so I will take a look myself if Jason doesn't beat me to it :).


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#97591
Avatar

Community saint

I really have zero familiarity with Twitter or FB as I have tried hard for a long time to not be sucked into those voids but I figured its time to give in cause they don't seem to be disappearing anytime soon.
Back to the top
 
Posted
Rating:
#97592
Avatar

Community saint

After Authorizing the APP I am given an OAuth Token and Secret should I be using these somewhere?
Back to the top
 
Posted
Rating:
#97593
Avatar

I'm going to call it a night, and I don't have the answer right now - I don't think I've tried this block myself yet. I'll probably step through this tomorrow. It could be some issues developed during v9 development, given that the git addons are auto-released.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#97594
Avatar

Community saint

Cool well I just got declined from FB to create a page for some reason (I think maybe I made the birthdate too young lol) anyway I'll keep trying to figure out how to get the FB rolling next. Yipee!
Back to the top
 
Posted
Rating:
#97597
Avatar

Community saint

I think the problem is related to a similar bug I need to fix in the YouTube Integration Block as well.  I don't have adequate error checking on parsing the feed.  If the feed is missing some elements (ie. no Tweets in your Twitter account), it may cause an error.

I'll try to get the code updated for both addons this week.

In the meantime, Duck, you can try adding a tweet to your Twitter account and then clear the block cache in your web site and see if it loads without error.
Back to the top
 
Posted
Rating:
#97598
Avatar

Community saint

You were bang on my sir! Adding a tweet solved it! thanks!
Back to the top
 
Posted
Rating:
#97602
Avatar

Thanks Jason. I just committed a fix for this actually, as I wanted to quickly check it out myself. I fixed the IS_STAFF thing, and added in a check for no tweets.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#97615
Avatar

Community saint

Great. Thanks Chris!
Back to the top
 
Posted
Rating:
#97776
Avatar

Community saint

This addon is crippled at the moment. It looks like Twitter killed off their version 1 REST API recently and are only supporting their version 1.1 JSON API, so I'll need to figure out a strategy and make the necessary changes to get this working again. The Twitter Feed Integration Block addon relies on the Twitter Support addon for the Twitter class (sources_custom/twitter.php) which is an older version of the Twitter class that doesn't use the version 1.1 JSON API. So, unless the newest version of the Twitter class is a simple drop in replacement for older versions, I may need to include a separate class to handle the Twitter calls. Stay tuned...



Last edit: by Jason Verhagen
Back to the top
 
Posted
Rating:
#97777
Avatar

Community saint

OK, not sure if this will have any other negative consequences, but anybody that needs to get this working should be able to get it working by changing one line in the sources_custom/twitter.php file.

Find the line that contains:

const API_URL = 'https://api.twitter.com/1';

and change it to:

const API_URL = 'https://api.twitter.com/1.1';

But this change hasn't yet been tested for the Twitter Support addon to ensure it doesn't break anything with Twitter syndication.
Back to the top
 
Posted
Rating:
#97781
Avatar

Shall I leave it to you to commit whatever needed to the v9 branch :)?


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#97795
Avatar

Community saint

Sure, I can commit the change to sources_custom/twitter.php in the v9 branch.  I haven't tested yet if the change will adversely affect the Twitter Support addon the twitter.php files belongs to.  I'll add a news or blog post to my site to be sure the Twitter syndication is still working.  I don't want to commit a change to another addon that fixes my addon but causes even more problems :)
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:
 Add topic 

Quick reply   Contract

Your name:
Your message: