Twitter api

    ICTscripters maakt gebruik van cookies. Door het gebruiken en browsen naar onze site gaat je automatisch akkoord met het gebruik van cookies. Klik hier voor meer informatie

    • Goedenavond,

      Ik ben opzoek naar iemand die een twitter api kan ontwikkelen, ik wil nieuws van een aantal sites kunnen plaatsen op twitter.

      Wat de api moet kunnen:

      - Nieuws van een site plaatsen
      Graag wil ik dat de api de titel van de nieuwsite tweet met de link erachter.

      Stel de titel op de site is: Ik zoek een twitter api, dan moet die titel dus getweet worden met de link.

      - Meerdere sites
      Ook zou het handig zijn dat het van meerdere sites komt, alleen wil ik dan graag dat er niet 2 keer hetzelfde nieuws wordt geplaatst, dus dat de api kijkt of er veel zelfde woorden in de titel zitten.


      Heeft u hier ervaring mee?
      Kunt u mij dan een pm sturen met uw prijs, en wanneer u het kunt aanleveren.

      MvG,

      R4
      :cheer:
      ---------

    • PHP Source Code

      1. (function($) {
      2. $.fn.tweet = function(o){
      3. var s = $.extend({
      4. username: null, // [string or array] required unless using the 'query' option; one or more twitter screen names
      5. list: null, // [string] optional name of list belonging to username
      6. favorites: false, // [boolean] display the user's favorites instead of his tweets
      7. query: null, // [string] optional search query
      8. avatar_size: null, // [integer] height and width of avatar if displayed (48px max)
      9. count: 1, // [integer] how many tweets to display?
      10. fetch: null, // [integer] how many tweets to fetch via the API (set this higher than 'count' if using the 'filter' option)
      11. retweets: true, // [boolean] whether to fetch (official) retweets (not supported in all display modes)
      12. intro_text: null, // [string] do you want text BEFORE your your tweets?
      13. outro_text: null, // [string] do you want text AFTER your tweets?
      14. join_text: null, // [string] optional text in between date and tweet, try setting to "auto"
      15. auto_join_text_default: "i said,", // [string] auto text for non verb: "i said" bullocks
      16. auto_join_text_ed: "i", // [string] auto text for past tense: "i" surfed
      17. auto_join_text_ing: "i am", // [string] auto tense for present tense: "i was" surfing
      18. auto_join_text_reply: "i replied to", // [string] auto tense for replies: "i replied to" @someone "with"
      19. auto_join_text_url: "i was looking at", // [string] auto tense for urls: "i was looking at" http:...
      20. loading_text: null, // [string] optional loading text, displayed while tweets load
      21. refresh_interval: null , // [integer] optional number of seconds after which to reload tweets
      22. twitter_url: "twitter.com", // [string] custom twitter url, if any (apigee, etc.)
      23. twitter_api_url: "api.twitter.com", // [string] custom twitter api url, if any (apigee, etc.)
      24. twitter_search_url: "search.twitter.com", // [string] custom twitter search url, if any (apigee, etc.)
      25. template: "{avatar}{text}{join}{time}", // [string or function] template used to construct each tweet <li> - see code for available vars
      26. comparator: function(tweet1, tweet2) { // [function] comparator used to sort tweets (see Array.sort)
      27. return tweet2["tweet_time"] - tweet1["tweet_time"];
      28. },
      29. filter: function(tweet) { // [function] whether or not to include a particular tweet (be sure to also set 'fetch')
      30. return true;
      31. }
      32. }, o);
      33. $.fn.extend({
      34. linkUrl: function() {
      35. var returning = [];
      36. // See http://daringfireball.net/2010/07/improved_regex_for_matching_urls
      37. var regexp = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»????]))/gi;
      38. this.each(function() {
      39. returning.push(this.replace(regexp,
      40. function(match) {
      41. var url = (/^[a-z]+:/i).test(match) ? match : "http://"+match;
      42. return "<a href=\""+url+"\">"+match+"</a>";
      43. }));
      44. });
      45. return $(returning);
      46. },
      47. linkUser: function() {
      48. var returning = [];
      49. var regexp = /[\@]+(\w+)/gi;
      50. this.each(function() {
      51. returning.push(this.replace(regexp,"@<a href=\"http://"+s.twitter_url+"/$1\">$1</a>"));
      52. });
      53. return $(returning);
      54. },
      55. linkHash: function() {
      56. var returning = [];
      57. // Support various latin1 (\u00**) and arabic (\u06**) alphanumeric chars
      58. var regexp = /(?:^| )[\#]+([\w\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff\u0600-\u06ff]+)/gi;
      59. var usercond = (s.username && s.username.length == 1) ? '&from='+s.username.join("%2BOR%2B") : '';
      60. this.each(function() {
      61. returning.push(this.replace(regexp, ' <a href="http://'+s.twitter_search_url+'/search?q=&tag=$1&lang=all'+usercond+'">#$1</a>'));
      62. });
      63. return $(returning);
      64. },
      65. capAwesome: function() {
      66. var returning = [];
      67. this.each(function() {
      68. returning.push(this.replace(/\b(awesome)\b/gi, '<span class="awesome">$1</span>'));
      69. });
      70. return $(returning);
      71. },
      72. capEpic: function() {
      73. var returning = [];
      74. this.each(function() {
      75. returning.push(this.replace(/\b(epic)\b/gi, '<span class="epic">$1</span>'));
      76. });
      77. return $(returning);
      78. },
      79. makeHeart: function() {
      80. var returning = [];
      81. this.each(function() {
      82. returning.push(this.replace(/(&lt;)+[3]/gi, "<tt class='heart'>&#x2665;</tt>"));
      83. });
      84. return $(returning);
      85. }
      86. });
      87. function parse_date(date_str) {
      88. // The non-search twitter APIs return inconsistently-formatted dates, which Date.parse
      89. // cannot handle in IE. We therefore perform the following transformation:
      90. // "Wed Apr 29 08:53:31 +0000 2009" => "Wed, Apr 29 2009 08:53:31 +0000"
      91. return Date.parse(date_str.replace(/^([a-z]{3})( [a-z]{3} \d\d?)(.*)( \d{4})$/i, '$1,$2$4$3'));
      92. }
      93. function relative_time(date) {
      94. var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
      95. var delta = parseInt((relative_to.getTime() - date) / 1000, 10);
      96. var r = '';
      97. if (delta < 60) {
      98. r = delta + ' seconden geleden';
      99. } else if(delta < 120) {
      100. r = 'een minuut geleden';
      101. } else if(delta < (45*60)) {
      102. r = (parseInt(delta / 60, 10)).toString() + ' minuten geleden';
      103. } else if(delta < (2*60*60)) {
      104. r = 'een uur geleden';
      105. } else if(delta < (24*60*60)) {
      106. r = '' + (parseInt(delta / 3600, 10)).toString() + ' uren geleden';
      107. } else if(delta < (48*60*60)) {
      108. r = 'een dag geleden';
      109. } else {
      110. r = (parseInt(delta / 86400, 10)).toString() + ' dagen geleden';
      111. }
      112. return 'Ongeveer ' + r;
      113. }
      114. function build_url() {
      115. var proto = ('https:' == document.location.protocol ? 'https:' : 'http:');
      116. var count = (s.fetch === null) ? s.count : s.fetch;
      117. if (s.list) {
      118. return proto+"//"+s.twitter_api_url+"/1/"+s.username[0]+"/lists/"+s.list+"/statuses.json?per_page="+count+"&callback=?";
      119. } else if (s.favorites) {
      120. return proto+"//"+s.twitter_api_url+"/favorites/"+s.username[0]+".json?count="+s.count+"&callback=?";
      121. } else if (s.query === null && s.username.length == 1) {
      122. return proto+'//'+s.twitter_api_url+'/1/statuses/user_timeline.json?screen_name='+s.username[0]+'&count='+count+(s.retweets ? '&include_rts=1' : '')+'&callback=?';
      123. } else {
      124. var query = (s.query || 'from:'+s.username.join(' OR from:'));
      125. return proto+'//'+s.twitter_search_url+'/search.json?&q='+encodeURIComponent(query)+'&rpp='+count+'&callback=?';
      126. }
      127. }
      128. return this.each(function(i, widget){
      129. var list = $('<ul class="tweet_list">').appendTo(widget);
      130. var intro = '<p class="tweet_intro">'+s.intro_text+'</p>';
      131. var outro = '<p class="tweet_outro">'+s.outro_text+'</p>';
      132. var loading = $('<p class="loading">'+s.loading_text+'</p>');
      133. if(s.username && typeof(s.username) == "string"){
      134. s.username = [s.username];
      135. }
      136. var expand_template = function(info) {
      137. if (typeof s.template === "string") {
      138. var result = s.template;
      139. for(var key in info) {
      140. var val = info[key];
      141. result = result.replace(new RegExp('{'+key+'}','g'), val === null ? '' : val);
      142. }
      143. return result;
      144. } else return s.template(info);
      145. };
      146. if (s.loading_text) $(widget).append(loading);
      147. $(widget).bind("load", function(){
      148. $.getJSON(build_url(), function(data){
      149. if (s.loading_text) loading.remove();
      150. if (s.intro_text) list.before(intro);
      151. list.empty();
      152. var tweets = $.map(data.results || data, function(item){
      153. var join_text = s.join_text;
      154. // auto join text based on verb tense and content
      155. if (s.join_text == "auto") {
      156. if (item.text.match(/^(@([A-Za-z0-9-_]+)) .*/i)) {
      157. join_text = s.auto_join_text_reply;
      158. } else if (item.text.match(/(^\w+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+) .*/i)) {
      159. join_text = s.auto_join_text_url;
      160. } else if (item.text.match(/^((\w+ed)|just) .*/im)) {
      161. join_text = s.auto_join_text_ed;
      162. } else if (item.text.match(/^(\w*ing) .*/i)) {
      163. join_text = s.auto_join_text_ing;
      164. } else {
      165. join_text = s.auto_join_text_default;
      166. }
      167. }
      168. // Basic building blocks for constructing tweet <li> using a template
      169. var screen_name = item.from_user || item.user.screen_name;
      170. var source = item.source;
      171. var user_url = "http://"+s.twitter_url+"/"+screen_name;
      172. var avatar_size = s.avatar_size;
      173. var avatar_url = item.profile_image_url || item.user.profile_image_url;
      174. var tweet_url = "http://"+s.twitter_url+"/"+screen_name+"/status/"+item.id_str;
      175. var retweet = (typeof(item.retweeted_status) != 'undefined');
      176. var retweeted_screen_name = retweet ? item.retweeted_status.user.screen_name : null;
      177. var tweet_time = parse_date(item.created_at);
      178. var tweet_relative_time = relative_time(tweet_time);
      179. var tweet_raw_text = retweet ? ('RT @'+retweeted_screen_name+' '+item.retweeted_status.text) : item.text; // avoid '...' in long retweets
      180. var tweet_text = $([tweet_raw_text]).linkUrl().linkUser().linkHash()[0];
      181. // Default spans, and pre-formatted blocks for common layouts
      182. var user = '<a class="tweet_user" href="'+user_url+'">'+screen_name+'</a>';
      183. var join = ((s.join_text) ? ('<span class="tweet_join"> '+join_text+' </span>') : ' ');
      184. var avatar = (avatar_size ?
      185. ('<a class="tweet_avatar" href="'+user_url+'"><img src="'+avatar_url+
      186. '" height="'+avatar_size+'" width="'+avatar_size+
      187. '" alt="'+screen_name+'\'s avatar" title="'+screen_name+'\'s avatar" border="0"/></a>') : '');
      188. var text = '<span class="tweet_text">'+$([tweet_text]).makeHeart().capAwesome().capEpic()[0]+ '</span>';
      189. var time = '<span class="tweet_time"><a href="'+tweet_url+'" title="Bekijk tweet op twitter">'+tweet_relative_time+'</a></span>';
      190. return { item: item, // For advanced users who want to dig out other info
      191. screen_name: screen_name,
      192. user_url: user_url,
      193. avatar_size: avatar_size,
      194. avatar_url: avatar_url,
      195. source: source,
      196. tweet_url: tweet_url,
      197. tweet_time: tweet_time,
      198. tweet_relative_time: tweet_relative_time,
      199. tweet_raw_text: tweet_raw_text,
      200. tweet_text: tweet_text,
      201. retweet: retweet,
      202. retweeted_screen_name: retweeted_screen_name,
      203. user: user,
      204. join: join,
      205. avatar: avatar,
      206. time: time,
      207. text: text
      208. };
      209. });
      210. tweets = $.grep(tweets, s.filter).slice(0, s.count);
      211. list.append($.map(tweets.sort(s.comparator),
      212. function(t) { return "<li>" + expand_template(t) + "</li>"; }).join('')).
      213. children('li:first').addClass('tweet_first').end().
      214. children('li:odd').addClass('tweet_even').end().
      215. children('li:even').addClass('tweet_odd');
      216. if (s.outro_text) list.after(outro);
      217. $(widget).trigger("loaded").trigger((tweets.length === 0 ? "empty" : "full"));
      218. if (s.refresh_interval) {
      219. window.setTimeout(function() { $(widget).trigger("load"); }, 1000 * s.refresh_interval);
      220. }
      221. });
      222. }).trigger("load");
      223. });
      224. };
      225. })(jQuery);
      Laat alles zien


      doet zichzelf vernieuwen bij pagina vernieuwen inladen met de nieuwste tweets met tijd en bericht en link, aparte .js van maken en includen in je html.

      html code:

      PHP Source Code

      1. <div class="tweet">
      2. </div>


      ps. niet door mij gemaakt ;) maar wel waar ik altijd mee werk :)
    • Dit weergeeft alle tweets die zijn gemaakt op een bepaald account (je kan instellen hoeveel er worden getoond etc).

      Het aanmaken van de tweets moet je een develop key aanvragen bij twitter, daar liggen standaard php api's klaar die easy to go uit te bouwen zijn, en door een simpele array() kan je er voor zorgen dat je op meerdere accounts twittert.

      (LET OP, elk twitter account heeft zijn eigen develop key, dus voor elk account waar je naartoe wilt twitteren moet je een eigen develop key neerzetten bij verzenden)