{"id":38440,"date":"2015-08-24T08:35:37","date_gmt":"2015-08-24T08:35:37","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/get-tweets-in-php\/"},"modified":"2016-12-28T14:59:02","modified_gmt":"2016-12-28T14:59:02","slug":"get-tweets-in-php","status":"publish","type":"plugin","link":"https:\/\/pcd.wordpress.org\/plugins\/get-tweets-in-php\/","author":14563771,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.2","stable_tag":"1.2","tested":"4.7.33","requires":"4.0","requires_php":"","requires_plugins":"","header_name":"Get Tweets in PHP","header_author":"Netgloo","header_description":"","assets_banners_color":"48464d","last_updated":"2016-12-28 14:59:02","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"","header_author_uri":"http:\/\/netgloo.com","rating":5,"author_block_rating":0,"active_installs":60,"downloads":3075,"num_ratings":2,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"2"},"assets_icons":{"icon.svg":{"filename":"icon.svg","revision":"1240948","resolution":"","location":"assets"}},"assets_banners":{"banner-772x250.png":{"filename":"banner-772x250.png","revision":"1240948","resolution":"772x250","location":"assets"}},"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.1","1.2"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[3772,7876,161,2080,159],"plugin_category":[56],"plugin_contributors":[88744,88743,88742],"plugin_business_model":[],"class_list":["post-38440","plugin","type-plugin","status-publish","hentry","plugin_tags-developers","plugin_tags-latest-tweets","plugin_tags-tweet","plugin_tags-tweets","plugin_tags-twitter","plugin_category-social-and-sharing","plugin_contributors-aboutnick","plugin_contributors-azanelli","plugin_contributors-netgloo","plugin_committers-azanelli"],"banners":{"banner":"https:\/\/ps.w.org\/get-tweets-in-php\/assets\/banner-772x250.png?rev=1240948","banner_2x":false,"banner_rtl":false,"banner_2x_rtl":false},"icons":{"svg":"https:\/\/ps.w.org\/get-tweets-in-php\/assets\/icon.svg?rev=1240948","icon":"https:\/\/ps.w.org\/get-tweets-in-php\/assets\/icon.svg?rev=1240948","icon_2x":false,"generated":false},"screenshots":[],"raw_content":"<!--section=description-->\n<p>This plugin will add the PHP class <code>GetTweetsInPhp<\/code>. You can use this class as described below for retrieving <strong>latest tweets<\/strong> from a Twitter account, then handle the tweets as you want in your PHP code.<\/p>\n\n<p><strong>Note<\/strong>: you should create a Twitter app before using this plugin. You can do it from here: <a href=\"http:\/\/apps.twitter.com\">http:\/\/apps.twitter.com<\/a>.<\/p>\n\n<h4>Features<\/h4>\n\n<ul>\n<li>Get latest N tweets from a Twitter account.<\/li>\n<li>Get the tweet's text formatted as HTML (with links for each entities).<\/li>\n<li>Cache support.<\/li>\n<li>Made for developers.<\/li>\n<li>Really light and simple.<\/li>\n<li>Works with the v1.1 Twitter API.<\/li>\n<li>Trivial install\/uninstall (only add\/remove the plugin's files).<\/li>\n<li>No any data will be permanently stored in your database (only transient data \nif the cache is enabled).<\/li>\n<li>Proudly coded by <a href=\"http:\/\/netgloo.com\/en\">Netgloo<\/a>.<\/li>\n<\/ul>\n\n<h4>Example usage<\/h4>\n\n<p>Get and show latest tweets from <a href=\"http:\/\/twitter.com\/netglooweb\">@netglooweb<\/a>:<\/p>\n\n<pre><code>\/\/ Set configurations\n$configs = [\n  \/\/ Set here tokens from your Twitter's app\n  'consumer_key' =&gt; 'CONSUMER_KEY', \n  'consumer_secret' =&gt; 'CONSUMER_SECRET',\n\n  \/\/ The Twitter account name\n  'screen_name' =&gt; 'netglooweb',\n\n  \/\/ The number of tweets\n  'count' =&gt; 5,\n];\n\n\/\/ Get latest tweets using the function get_tweets\n$tweets = \\Netgloo\\GetTweetsInPhp::get_tweets($configs);\n\n\/\/ ...\n\n\/\/ For each tweet show the HTML text and the attached image\nforeach ($tweets as $tweet) {\n\n  echo \"&lt;p&gt;\";\n  echo $tweet-&gt;n_html_text;\n\n  if ($tweet-&gt;n_has_media_photo) {\n    echo \"&lt;img src='{$tweet-&gt;n_media_photo_url}' width='100%' \/&gt;\";\n  }\n\n  echo \"&lt;\/p&gt;\";\n\n}\n\n\/\/ ...\n<\/code><\/pre>\n\n<p>That's all! Have fun!<\/p>\n\n<h4>Configurations<\/h4>\n\n<p>The <code>get_tweets()<\/code> function takes an array of configurations:<\/p>\n\n<pre><code>$configs = [\n\n  \/\/ --- Required ---\n\n  \/\/ The tokens from your Twitter's app\n  'consumer_key' =&gt; '...',\n  'consumer_secret' =&gt; '...',\n\n  \/\/ The Twitter account name\n  'screen_name' =&gt; '...',\n\n\n  \/\/ --- Optional ---\n\n  \/\/ The number of tweets\n  'count' =&gt; 20,\n\n  \/\/ Include also the retweets\n  'include_rts' =&gt; true,\n\n  \/\/ In the HTML text will be showed \"Retweeted by ...\" if the tweet\n  \/\/ is a retweet\n  'show_retweeted_by' =&gt; true,\n\n  \/\/ Enable the cache\n  \/\/ It is recommended to activate the cache, when you put live \n  \/\/ your website, in order to avoid to reach the Twitter's api rate\n  \/\/ limit of 300 requests \/ 15-min.\n  'cache_enabled' =&gt; false,\n\n  \/\/ Cache expiration (in seconds)\n  \/\/ Increase the value to optimize the website's speed, decrease\n  \/\/ the value if you want a more real-time behaviour (but not\n  \/\/ less than 4 seconds to avoid to reach the rate limit).\n  'cache_expiration' =&gt; 60,\n\n  \/\/ Templates\n\n  \/\/ Retweeted by text template\n  'retweeted_by_template' =&gt; \n    '&lt;em&gt; Retweeted by {{user_name}}&lt;\/em&gt;',\n\n  \/\/ Hash tag link template\n  'hashtag_link_template' =&gt; \n    '&lt;a href=\"{{hashtag_link}}\" rel=\"nofollow\" target=\"_blank\"&gt;' .\n    '#{{hashtag_text}}&lt;\/a&gt;',\n\n  \/\/ Url link template\n  'url_link_template' =&gt; \n    '&lt;a href=\"{{url_link}}\" rel=\"nofollow\" target=\"_blank\" ' .\n    'title=\"{{url_title}}\"&gt;{{url_text}}&lt;\/a&gt;',\n\n  \/\/ User mention link template\n  'user_mention_link_template' =&gt; \n    '&lt;a href=\"{{user_mention_link}}\" rel=\"nofollow\" target=\"_blank\" ' .\n    'title=\"{{user_mention_title}}\"&gt;@{{user_mention_text}}&lt;\/a&gt;',\n\n  \/\/ Media link template\n  'media_link_template' =&gt; \n    '&lt;a href=\"{{media_link}}\" rel=\"nofollow\" target=\"_blank\" ' .\n    'title=\"{{media_title}}\"&gt;{{media_text}}&lt;\/a&gt;'\n\n];\n\n$tweets = \\Netgloo\\GetTweetsInPhp::get_tweets($configs);\n<\/code><\/pre>\n\n<h4>Returned values<\/h4>\n\n<p>The <code>get_tweets()<\/code> function will return an Array of tweets. On each tweet object are available these properties:<\/p>\n\n<ul>\n<li><code>n_html_text<\/code> (String) The tweet text formatted as HTML, with links on each entities.<\/li>\n<li><code>n_is_retweeted<\/code> (Boolean) True if the curret tweet is a retweet.<\/li>\n<li><code>n_has_media_photo<\/code> (Boolean) True if the current tweet has an attached photo.<\/li>\n<li><code>n_media_photo_url<\/code> (String) The url of the tweet's attached photo.<\/li>\n<li><code>n_media_photo_urls<\/code> (Array) If the tweet has more than one attached photos this properties contains all the urls.<\/li>\n<\/ul>\n\n<p>Other available properties are those returned from the <a href=\"https:\/\/dev.twitter.com\/rest\/reference\/get\/statuses\/user_timeline\">user_timeline Twitter's API<\/a>.\nThese are some useful ones:<\/p>\n\n<ul>\n<li><code>created_at<\/code><\/li>\n<li><code>retweet_count<\/code><\/li>\n<li><code>user-&gt;name<\/code><\/li>\n<li><code>user-&gt;screen_name<\/code><\/li>\n<li><code>user-&gt;profile_image_url<\/code><\/li>\n<\/ul>\n\n<p>If the properties <code>n_is_retweeted<\/code> is true the current tweet is a \"re-tweet\" and the <code>retweeted_status<\/code> object is available:<\/p>\n\n<ul>\n<li><code>retweeted_status-&gt;user-&gt;name<\/code><\/li>\n<li><code>retweeted_status-&gt;user-&gt;screen_name<\/code><\/li>\n<li><code>retweeted_status-&gt;retweet_count<\/code><\/li>\n<\/ul>\n\n<p><strong>Example<\/strong><\/p>\n\n<p>This code use some of the above properties:<\/p>\n\n<pre><code>\/\/ ...\n\n$tweets = \\Netgloo\\GetTweetsInPhp::get_tweets($configs);\n\nforeach ($tweets as $tweet) {\n  echo $tweet-&gt;created_at . \"&lt;br\/&gt;\";\n  echo $tweet-&gt;n_html_text . \"&lt;br\/&gt;\";\n  if ($tweet-&gt;n_has_media_photo) {\n    echo $tweet-&gt;n_media_photo_url  . \"&lt;br\/&gt;\";\n  }\n}\n\n\/\/ ...\n<\/code><\/pre>\n\n<h4>Limitations<\/h4>\n\n<p>Since we rely on the Twitter's <code>user_timeline<\/code> API, you should read the following docs for taking in account any API's limitation:<\/p>\n\n<ul>\n<li>https:\/\/dev.twitter.com\/rest\/reference\/get\/statuses\/user_timeline<\/li>\n<li>https:\/\/dev.twitter.com\/rest\/public\/timelines<\/li>\n<\/ul>\n\n<h4>Contributing<\/h4>\n\n<p>For patches, bug reports, suggestions, requests for features there is a Git repository on GitHub here:\nhttps:\/\/github.com\/netgloo\/get-tweets-in-php<\/p>\n\n<!--section=installation-->\n<h4>Requirements<\/h4>\n\n<p>To work this plugin, following component need to be installed in your server.<\/p>\n\n<ul>\n<li>PHP version 5.3 or higher<\/li>\n<li>cURL<\/li>\n<li>WordPress 4.2.2 or higher<\/li>\n<\/ul>\n\n<h4>Install<\/h4>\n\n<p>Put the plugin to your Wordpress' plugins folder and activate it from the Admin Backend.<\/p>\n\n<h4>Uninstall<\/h4>\n\n<p>Just delete the plugin from Wordpress.<\/p>\n\n<!--section=faq-->\n<dl>\n<dt>Why the \"n\" before your custom tweet's properties?<\/dt>\n<dd><p>Our custom properties (i.e. properties not from the Twitter's API) are prefixed with an \"n\". The \"n\" is the first character in \"Netgloo\" ;).<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>1.2<\/h4>\n\n<ul>\n<li>Custom HTML templates for links and \"retweeted by\" text.<\/li>\n<li>New hashtag link: https:\/\/twitter.com\/hashtag.<\/li>\n<li>Get media urls with https.<\/li>\n<li>Cache disabled by default (as in the documentation).<\/li>\n<\/ul>\n\n<h4>1.1<\/h4>\n\n<ul>\n<li>Bug fix setting transient cache name.<\/li>\n<\/ul>\n\n<h4>1.0<\/h4>\n\n<ul>\n<li>First release.<\/li>\n<\/ul>","raw_excerpt":"Get latest tweets from a Twitter account with a couple of lines of PHP, and do anything you want with them.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/38440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=38440"}],"author":[{"embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/azanelli"}],"wp:attachment":[{"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=38440"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=38440"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=38440"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=38440"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=38440"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/pcd.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=38440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}