8 Replies - 3685 Views - Last Post: 19 February 2010 - 10:02 AM

#4 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Tips For Those Who Want To Use The Twitter API

Post icon  Posted 30 July 2009 - 02:38 PM

Well I recently was working on a Twitter API wrapper DLL, and figured out some interesting points I would like to share with eveyone who intends to work with the Twitter API from a desktop app.

1. XML is the base of the Twitter API - Twitter API is heavily based on XML. Almost all the API calls return some data in XML format (either plain XML, Atom or RSS). Therefore a good knowledge of what is XML and how to use it in your programming language of choice is a must.

2. JSON is also available - For the most API calls the returned data can be obtained in JSON format too, so if you are used to this instead of XML, then you can apply it to the fullest. I had some troubles using JSON in .NET (there are several calls that only return JSON data), but there are third-party libraries that will help you out on that.

3. Nowhere without HTTP requests - The vast majority of API calls relies on different HTTP requests (GET, POST and DELETE). Therefore, you should have a good understanding on how those work and how to apply those to get and post information.

4. MIME Types - That's yet another thing you should be familiar with. Some request need to be sent with form data, while other ones need to contain raw multipart data to be correctly processed. Same refers to images. Basically, the only MIME types I was using were application/x-www-form-urlencoded, multipart/form-data and various image types (JPEG, PNG and GIF).

5. Use custom classes - Twitter API calls return a lot of XML/JSON data and you need to somehow store and process it. My first thought was about using arrays, but then I figured that this wasn't the most efficient solution in this case. Create custom classes with settable fields that will store the returned data. Be sure, that you will use the same class more than once.

6. The original Twitter API Documentation is not the limit - There are not too many web sites out there to explain you how to buid the Twitter API calls in your language and sometimes you might see that you cannot implement a call. What to do in this case? Just leave it like this? Nope. Ask the pros and Twitter API developers on Twitter Development Talk. That group is rather useful when you are stuck on something and it can give you some help on implementing the call.

7. Basic Authentication is not there for long - Many of those who study the Twitter API use the basic authentication methods. However, it is not going to be there for long according to Twitter developers. It is steadily replaced with OAuth and if you want to register your application, you will need to implement OAuth authorization to send the unique application token.

8. Many API calls require authentication - Make sure the end user provides the needed credentials to use that specific API call. It is not that hard to implement two additional method arguments that will ask for the username and password.

9. Know the HTTP response codes - Take a look at this list of HTTP response codes. This is very helpful when a API call is unsuccessful and you have to figure out what happned. On a sidenote, always get the raw HTTP response to see the actual error.

10. Watch for API updates - Sometimes, the API updates come unexpected and the whole block of API calls in your application might not work. For example, a while ago Twitter introduced the Expect 100-Continue header and it is still required to perform HTTP requests. The best way to keep in touch with the updates is to regularly watch the Twitter API Documentation Wiki page (especially the Recent Activity section).

Everything in this post comes from my own experience with building a DLL that is a Twitter API wrapper. If anyone else wants to add some piece of advice, they are more than welcome to do so. :)
Was This Post Helpful? 3

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tips For Those Who Want To Use The Twitter API

Posted 30 July 2009 - 02:50 PM

Excellent stuff Core! I'm in the planning stages of a Twitter application myself (struggling with whether I want to make it web based of desktop application), so this will come in handy.
Was This Post Helpful? 0
  • +
  • -

#6 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Tips For Those Who Want To Use The Twitter API

Posted 30 July 2009 - 03:00 PM

@PsychoCoder I remember you started a project called PsychoTwitter in the Share Your Project forum. Is it still active?

Actually, just a note - Twitter API is not that hard as it seems to be after you implement 4-5 calls, as the same principles will apply to pretty much everything (but OAuth).
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Tips For Those Who Want To Use The Twitter API

Posted 30 July 2009 - 03:02 PM

@Core: It's still active, I've just had so many paying projects that personal ones were put on the back-burner. I plan on reviving it once I get more time. I've got some of the planning done, a lot of the wrapper completed so I did get some done
Was This Post Helpful? 0
  • +
  • -

#8 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Tips For Those Who Want To Use The Twitter API

Posted 30 July 2009 - 03:10 PM

@PsychoCoder So, if there will be any help needed with that, I will be glad to apply my knowledge. I have my library (dotTweet) having almost 95% of the API calls implemented, so since it is open-source, you could use some of that in the app.
Was This Post Helpful? 0
  • +
  • -

#9 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

Re: Tips For Those Who Want To Use The Twitter API

Posted 31 July 2009 - 12:49 PM

Excellent stuff, thanks for posting it! :^:

I really like this e-mail with the featured topics.
Was This Post Helpful? 0
  • +
  • -

#10 Nameless1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 16-July 09

Re: Tips For Those Who Want To Use The Twitter API

Posted 01 August 2009 - 04:33 AM

nice topic ;)
Was This Post Helpful? 0
  • +
  • -

#11 Sumit Thakur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 06-February 10

Re: Tips For Those Who Want To Use The Twitter API

Posted 07 February 2010 - 09:21 PM

Thanks for this great stuff...
well we have created a website (www.txt2mkts.com) to send messages to USA only for our client.
we have used 3-4 gateways to send sms.
But when i looked at twitter api, i liked it very much from rest of the api's i have used.
Now i am looking forward to use it..

But i m just confused....
Can i send messages to any country...
and what charges twitter and service providers will charge..
i m waiting for ur reply

thanks and regards,
Sumit Thakur
Software Daveloper,
Altruist technologies,
www.altruistindia.com
Was This Post Helpful? 0
  • +
  • -

#12 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Tips For Those Who Want To Use The Twitter API

Posted 19 February 2010 - 10:02 AM

Twitter is a web service, it is not country-based. And Twitter is a free service, therefore the developers and regular users aren't charged for using it. If the someone accesses it from a mobile device, he/she might be charged for the traffic used. It works on a principle, different from the SMS one, so you have to fully understand what it is before implementing it's API in your project.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1