SlideShare a Scribd company logo
1 of 18
Twitter API Integration PHP, MySQL, Apache & Me
API API & More API
Search API Methods  search trends trends/current trends/daily trends/weekly   REST API Methods   Timeline Methods statuses/public_timeline  statuses/home_timeline statuses/friends_timeline statuses/user_timeline  statuses/mentions statuses/retweeted_by_me statuses/retweeted_to_me statuses/retweets_of_me  Status Methods statuses/show statuses/update statuses/destroy   statuses/retweet statuses/retweets statuses/id/retweeted_by  statuses/id/retweeted_by/ids  User Methods users/show  users/lookup users/search users/suggestions users/suggestions/category statuses/friends statuses/followers  List Methods          POST lists      (create)          POST lists id  (update)          GET lists        (index)          GET list id      (show)          DELETE list id (destroy)          GET list statuses          GET list memberships          GET list subscriptions  List Members Methods          GET list members          POST list members          DELETE list members          GET list members id  List Subscribers Methods          GET list subscribers          POST list subscribers          DELETE list subscribers          GET list subscribers id  Direct Message Methods  direct_messages direct_messages/sent direct_messages/new direct_messages/destroy  API API & More API
Spam Reporting Methods   report_spam  Saved Searches Methods saved_searches saved_searches/show saved_searches/create saved_searches/destroy OAuth Methods oauth/request_token oauth/authorize oauth/authenticate oauth/access_token   Geo methods geo/nearby_places   geo/reverse_geocode   geo/id   Friendship Methods friendships/create friendships/destroy  friendships/exists friendships/show friendships/incoming friendships/outgoing     Account Methods account/verify_credentials  account/rate_limit_status account/end_session account/update_delivery_device  account/update_profile_colors  account/update_profile_image  account/update_profile_background_image account/update_profile   Favorite Methods favorites favorites/create   favorites/destroy   Notification Methods notifications/follow  notifications/leave   Block Methods blocks/create   blocks/destroy blocks/exists blocks/blocking blocks/blocking/ids Social Graph Methods friends/ids    followers/ids    API API & More API
Latest Trends on Twitter as We Speak function getlatest(){	$url = 'http://search.twitter.com/trends/current.json?exclude=hashtags';	// create a new cURL resource	$ch = curl_init();// set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // grab URL and pass it to the browser$json=curl_exec($ch);curl_close($ch);$obj_t=json_decode($json,true);echo “Latest Trends Today on Twitter.com @" .date('l jS f F Y h:i:s A‘)" ;}
Display Function (Array) function display($i_array) { foreach ($i_array as $i => $val) 	{ 	// check if element is array and trends only	 	if (is_array($val)){ 	 display($val);} 		else 		{ 		if($i=='name')	{ 		echo "<a href='http://twitter.com/search?q=$val'>$val</a><br>"; 			} 		  } 	} // end for }
Display Friends function display_following($screen_name) { if (!($screen_name=="")) { $url = 'http://api.twitter.com/1/statuses/friends.xml?screen_name='.$screen_name ; $xml = simplexml_load_file($url) or exit ("Unable to load XML!");  echo "<div id='result'>"; echo "<b>You Follow " .count($xml->user) ." Users</b><br>"; echo "<table>"; echo "<tr>"; $count = 0; foreach ($xml as $user => $u)  {  if ($count==3) {echo "</tr>"; $count=0;}   echo "<td><a href='http://twitter.com/$u->screen_name'>"   ."<img height='50' width='50' title=".$u->screen_name ." src='" .$u->profile_image_url ."'/>" ."</a></td>";       $count = $count + 1; }  echo "</tr></table>"; echo "</div>"; } else {} }//end display_following()
DisplayFollowers function display_followers($screen_name) { 	if (!($screen_name=="")) 	{ 		$curl_conn = curl_init(); 		$url = 'http://twitter.com/statuses/followers/' .$screen_name .'.xml'; 		$xml = simplexml_load_file($url) or exit ("Unable to load XML!");  		echo "<div id='result'>"; 		echo "<b>Your " .count($xml->user) ." Followers</b><br>"; 		echo "<table>"; 		echo "<tr>"; 		$count = 0; foreach ($xml as $user => $u)  		{  		if ($count==3) 		{echo "</tr>“;	$count=0;} 		  echo "<td><a href='http://twitter.com/$u->screen_name'>" 	 ."<img height='50' width='50' title=".$u->screen_name ." src='".$u->profile_image_url ."'/>"  	."</a></td>";     		 $count = $count + 1; 		} //end for 		echo "</tr></table>"; 		echo "</div>"; 	}  	else 	{ 	//display_form(); 	} }//end display_followers()
Add Tweet function post($username,$password,$tweet) { $status = urlencode(stripslashes(urldecode($_POST['tweet']))); if ($status) { $tweetUrl = 'http://www.twitter.com/statuses/update.xml'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "$tweetUrl"); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status"); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($curl); $resultArray = curl_getinfo($curl); 	if ($resultArray['http_code'] == 200) 	{ 		//echo 'Tweet Posted'; 		display(); 	} 	else 	{ 		echo 'Could not post Tweet to Twitter right now. Try again later.'; display_form(); 	} curl_close($curl); 	} // end status }//end post
Linkify function linkify($text)       {   $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_.~#?&//=]+)‘,         '<a href="1">1</a>', $text);   text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_.~#?&//=]+)‘, '1<a href="http://2">2</a>', $text);   $text = eregi_replace('([_0-9a-z-]+@([0-9a-z][0-9a-z-]+)+[a-z]{2,3})‘,      '<a href="mailto:1">1</a>', $text);   return $text;       }
Like Shorter URLS function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1') { 	//create the URL 	$bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format; 	//get the url 	//could also use cURL here 	$response = file_get_contents($bitly); 	//parse depending on desired format 	if(strtolower($format) == 'json') 	{ 		$json = @json_decode($response,true); 		return $json['results'][$url]['shortUrl']; 	} 	else //xml 	{ 		$xml = simplexml_load_string($response); 		return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash; 	} } /* usage */ $short = make_bitly_url($_GET['url'],'davidwalshblog','R_9acc320c5c423e4f5192e00ff24980','json'); //echo 'The short URL for "http://www.devitsolutions.com" is:  <a style="color:Green" href='.$short .'>Link</a>';  echo $short;
Last status function get_status($twitter_id, $hyperlinks = true) {     $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);     $src = curl_exec($c); curl_close($c); preg_match('/<text>(.*)<text>/', $src, $m);     $status = htmlentities($m[1]);     if( $hyperlinks )  $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=quot;0quot;>0</a>", $status);     return($status); }
LIVE DEMO WWW.iwilltypeurl.com
THANKS TWITTER , IBM AND HOW CAN I FORGET U ALL
CATCH ME ON TWITTER @utpalbetai

More Related Content

What's hot

Google search techniques
Google search techniquesGoogle search techniques
Google search techniquesOusman Faal
 
Webinar: Online Fundraising
Webinar: Online FundraisingWebinar: Online Fundraising
Webinar: Online FundraisingifPeople
 
Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011Juan Sequeda
 
funP 麻吉 開發者俱樂部十月份聚會
funP 麻吉 開發者俱樂部十月份聚會funP 麻吉 開發者俱樂部十月份聚會
funP 麻吉 開發者俱樂部十月份聚會Nathan Chiu
 

What's hot (9)

Google search techniques
Google search techniquesGoogle search techniques
Google search techniques
 
Webinar: Online Fundraising
Webinar: Online FundraisingWebinar: Online Fundraising
Webinar: Online Fundraising
 
Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011Creating Linked Data 2/5 Semtech2011
Creating Linked Data 2/5 Semtech2011
 
Oo Perl
Oo PerlOo Perl
Oo Perl
 
Seoptimizing
SeoptimizingSeoptimizing
Seoptimizing
 
Ruby on discuz
Ruby on discuzRuby on discuz
Ruby on discuz
 
mmiuc
mmiucmmiuc
mmiuc
 
funP 麻吉 開發者俱樂部十月份聚會
funP 麻吉 開發者俱樂部十月份聚會funP 麻吉 開發者俱樂部十月份聚會
funP 麻吉 開發者俱樂部十月份聚會
 
google dork.pdf
google dork.pdfgoogle dork.pdf
google dork.pdf
 

Similar to Twitter API Integration PHP Methods Guide

Similar to Twitter API Integration PHP Methods Guide (20)

Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Forum Presentation
Forum PresentationForum Presentation
Forum Presentation
 
JQuery 101
JQuery 101JQuery 101
JQuery 101
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Php 3 1
Php 3 1Php 3 1
Php 3 1
 
State Machines to State of the Art
State Machines to State of the ArtState Machines to State of the Art
State Machines to State of the Art
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
The Basics Of Page Creation
The Basics Of Page CreationThe Basics Of Page Creation
The Basics Of Page Creation
 
Open Hack 2008 Mybloglog
Open Hack 2008 MybloglogOpen Hack 2008 Mybloglog
Open Hack 2008 Mybloglog
 
Web Scraping with PHP
Web Scraping with PHPWeb Scraping with PHP
Web Scraping with PHP
 
Evolution of API With Blogging
Evolution of API With BloggingEvolution of API With Blogging
Evolution of API With Blogging
 
Component and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHPComponent and Event-Driven Architectures in PHP
Component and Event-Driven Architectures in PHP
 
PHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the GoodPHP 102: Out with the Bad, In with the Good
PHP 102: Out with the Bad, In with the Good
 
Zend Form Tutorial
Zend Form TutorialZend Form Tutorial
Zend Form Tutorial
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
Meetup django common_problems(1)
Meetup django common_problems(1)Meetup django common_problems(1)
Meetup django common_problems(1)
 
Php Basic Security
Php Basic SecurityPhp Basic Security
Php Basic Security
 
Further Php
Further PhpFurther Php
Further Php
 
Haml & Sass presentation
Haml & Sass presentationHaml & Sass presentation
Haml & Sass presentation
 

More from Utpal Betai

Decentralised Financing (DeFi)
Decentralised Financing (DeFi)Decentralised Financing (DeFi)
Decentralised Financing (DeFi)Utpal Betai
 
Gdg dev fest 2019
Gdg dev fest 2019Gdg dev fest 2019
Gdg dev fest 2019Utpal Betai
 
Keynote focus on future
Keynote focus on future Keynote focus on future
Keynote focus on future Utpal Betai
 
Keynote Android
Keynote Android Keynote Android
Keynote Android Utpal Betai
 
Top 10 app developer excuses
Top 10 app developer excusesTop 10 app developer excuses
Top 10 app developer excusesUtpal Betai
 
Apple design awards 2014
Apple design awards 2014Apple design awards 2014
Apple design awards 2014Utpal Betai
 
I os8 in 8 slides
I os8 in 8 slidesI os8 in 8 slides
I os8 in 8 slidesUtpal Betai
 
Mobile app for Business Success
Mobile app for Business SuccessMobile app for Business Success
Mobile app for Business SuccessUtpal Betai
 
Google Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneGoogle Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneUtpal Betai
 
Google mirror api
Google mirror apiGoogle mirror api
Google mirror apiUtpal Betai
 
App monetization
App monetizationApp monetization
App monetizationUtpal Betai
 

More from Utpal Betai (16)

Decentralised Financing (DeFi)
Decentralised Financing (DeFi)Decentralised Financing (DeFi)
Decentralised Financing (DeFi)
 
Gdg dev fest 2019
Gdg dev fest 2019Gdg dev fest 2019
Gdg dev fest 2019
 
Keynote focus on future
Keynote focus on future Keynote focus on future
Keynote focus on future
 
Keynote 2017
Keynote   2017 Keynote   2017
Keynote 2017
 
Keynote Android
Keynote Android Keynote Android
Keynote Android
 
Top 10 app developer excuses
Top 10 app developer excusesTop 10 app developer excuses
Top 10 app developer excuses
 
Apple design awards 2014
Apple design awards 2014Apple design awards 2014
Apple design awards 2014
 
Appmonetization
AppmonetizationAppmonetization
Appmonetization
 
I os8 in 8 slides
I os8 in 8 slidesI os8 in 8 slides
I os8 in 8 slides
 
Eye opener
Eye openerEye opener
Eye opener
 
Mobile app for Business Success
Mobile app for Business SuccessMobile app for Business Success
Mobile app for Business Success
 
Google Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer ZoneGoogle Glass Development Kit - Developer Zone
Google Glass Development Kit - Developer Zone
 
Google mirror api
Google mirror apiGoogle mirror api
Google mirror api
 
Androit kitkat
Androit kitkatAndroit kitkat
Androit kitkat
 
App monetization
App monetizationApp monetization
App monetization
 
Led money
Led moneyLed money
Led money
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Twitter API Integration PHP Methods Guide

  • 1. Twitter API Integration PHP, MySQL, Apache & Me
  • 2.
  • 3.
  • 4.
  • 5. API API & More API
  • 6. Search API Methods  search trends trends/current trends/daily trends/weekly   REST API Methods   Timeline Methods statuses/public_timeline  statuses/home_timeline statuses/friends_timeline statuses/user_timeline  statuses/mentions statuses/retweeted_by_me statuses/retweeted_to_me statuses/retweets_of_me  Status Methods statuses/show statuses/update statuses/destroy   statuses/retweet statuses/retweets statuses/id/retweeted_by  statuses/id/retweeted_by/ids  User Methods users/show  users/lookup users/search users/suggestions users/suggestions/category statuses/friends statuses/followers  List Methods          POST lists      (create)          POST lists id  (update)          GET lists        (index)          GET list id      (show)          DELETE list id (destroy)          GET list statuses          GET list memberships          GET list subscriptions  List Members Methods          GET list members          POST list members          DELETE list members          GET list members id  List Subscribers Methods          GET list subscribers          POST list subscribers          DELETE list subscribers          GET list subscribers id  Direct Message Methods  direct_messages direct_messages/sent direct_messages/new direct_messages/destroy  API API & More API
  • 7. Spam Reporting Methods   report_spam  Saved Searches Methods saved_searches saved_searches/show saved_searches/create saved_searches/destroy OAuth Methods oauth/request_token oauth/authorize oauth/authenticate oauth/access_token   Geo methods geo/nearby_places   geo/reverse_geocode   geo/id   Friendship Methods friendships/create friendships/destroy  friendships/exists friendships/show friendships/incoming friendships/outgoing     Account Methods account/verify_credentials  account/rate_limit_status account/end_session account/update_delivery_device  account/update_profile_colors  account/update_profile_image  account/update_profile_background_image account/update_profile   Favorite Methods favorites favorites/create   favorites/destroy   Notification Methods notifications/follow  notifications/leave   Block Methods blocks/create   blocks/destroy blocks/exists blocks/blocking blocks/blocking/ids Social Graph Methods friends/ids    followers/ids    API API & More API
  • 8. Latest Trends on Twitter as We Speak function getlatest(){ $url = 'http://search.twitter.com/trends/current.json?exclude=hashtags'; // create a new cURL resource $ch = curl_init();// set URL and other appropriate optionscurl_setopt($ch, CURLOPT_URL,$url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // grab URL and pass it to the browser$json=curl_exec($ch);curl_close($ch);$obj_t=json_decode($json,true);echo “Latest Trends Today on Twitter.com @" .date('l jS f F Y h:i:s A‘)" ;}
  • 9. Display Function (Array) function display($i_array) { foreach ($i_array as $i => $val) { // check if element is array and trends only if (is_array($val)){ display($val);} else { if($i=='name') { echo "<a href='http://twitter.com/search?q=$val'>$val</a><br>"; } } } // end for }
  • 10. Display Friends function display_following($screen_name) { if (!($screen_name=="")) { $url = 'http://api.twitter.com/1/statuses/friends.xml?screen_name='.$screen_name ; $xml = simplexml_load_file($url) or exit ("Unable to load XML!"); echo "<div id='result'>"; echo "<b>You Follow " .count($xml->user) ." Users</b><br>"; echo "<table>"; echo "<tr>"; $count = 0; foreach ($xml as $user => $u) { if ($count==3) {echo "</tr>"; $count=0;} echo "<td><a href='http://twitter.com/$u->screen_name'>" ."<img height='50' width='50' title=".$u->screen_name ." src='" .$u->profile_image_url ."'/>" ."</a></td>"; $count = $count + 1; } echo "</tr></table>"; echo "</div>"; } else {} }//end display_following()
  • 11. DisplayFollowers function display_followers($screen_name) { if (!($screen_name=="")) { $curl_conn = curl_init(); $url = 'http://twitter.com/statuses/followers/' .$screen_name .'.xml'; $xml = simplexml_load_file($url) or exit ("Unable to load XML!"); echo "<div id='result'>"; echo "<b>Your " .count($xml->user) ." Followers</b><br>"; echo "<table>"; echo "<tr>"; $count = 0; foreach ($xml as $user => $u) { if ($count==3) {echo "</tr>“; $count=0;} echo "<td><a href='http://twitter.com/$u->screen_name'>" ."<img height='50' width='50' title=".$u->screen_name ." src='".$u->profile_image_url ."'/>" ."</a></td>"; $count = $count + 1; } //end for echo "</tr></table>"; echo "</div>"; } else { //display_form(); } }//end display_followers()
  • 12. Add Tweet function post($username,$password,$tweet) { $status = urlencode(stripslashes(urldecode($_POST['tweet']))); if ($status) { $tweetUrl = 'http://www.twitter.com/statuses/update.xml'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "$tweetUrl"); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status"); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($curl); $resultArray = curl_getinfo($curl); if ($resultArray['http_code'] == 200) { //echo 'Tweet Posted'; display(); } else { echo 'Could not post Tweet to Twitter right now. Try again later.'; display_form(); } curl_close($curl); } // end status }//end post
  • 13. Linkify function linkify($text) { $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_.~#?&//=]+)‘, '<a href="1">1</a>', $text); text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_.~#?&//=]+)‘, '1<a href="http://2">2</a>', $text); $text = eregi_replace('([_0-9a-z-]+@([0-9a-z][0-9a-z-]+)+[a-z]{2,3})‘, '<a href="mailto:1">1</a>', $text); return $text; }
  • 14. Like Shorter URLS function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1') { //create the URL $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format; //get the url //could also use cURL here $response = file_get_contents($bitly); //parse depending on desired format if(strtolower($format) == 'json') { $json = @json_decode($response,true); return $json['results'][$url]['shortUrl']; } else //xml { $xml = simplexml_load_string($response); return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash; } } /* usage */ $short = make_bitly_url($_GET['url'],'davidwalshblog','R_9acc320c5c423e4f5192e00ff24980','json'); //echo 'The short URL for "http://www.devitsolutions.com" is: <a style="color:Green" href='.$short .'>Link</a>'; echo $short;
  • 15. Last status function get_status($twitter_id, $hyperlinks = true) { $c = curl_init(); curl_setopt($c, CURLOPT_URL, "http://twitter.com/statuses/user_timeline/$twitter_id.xml?count=1"); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); $src = curl_exec($c); curl_close($c); preg_match('/<text>(.*)<text>/', $src, $m); $status = htmlentities($m[1]); if( $hyperlinks ) $status = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=quot;0quot;>0</a>", $status); return($status); }
  • 17. THANKS TWITTER , IBM AND HOW CAN I FORGET U ALL
  • 18. CATCH ME ON TWITTER @utpalbetai