Oct 6, 2011

Twitter API ME 1.8: Now with OAuth support

Hi, all

It's been a long time since my last post, but besides being a little bit busy, I also took a vacation, enjoying a trip to US, to visit some old friends. Great trip, by the way. But now, let's get back to work!

One thing that kept me busy during this time was the implementation of Twitter API ME 1.8. This new version is very special, because it comes with full support to OAuth. Since Twitter changed its Application Permission Model, requiring apps to use OAuth to have access to user's direct messages, Twitter API ME developers were not longer able to access DMs from their apps. Before v1.8, only xAuth was supported.

Other great thing about OAuth is that developers will no longer need to request xAuth permission to Twitter for their apps keys, in order to start working with the API. Since OAuth flow is more secure, Twitter trusts promptly any registered app, because there is no way for apps to get access to user's password. So, no more you have to wait days or until your app is done, so Twitter decides to grant you permission.

It is also important to point out, OAuth is available for all platforms supported: Java ME, Android and RIM.

Besides OAuth, Twitter API ME 1.8 comes with other news:

- Possibility to configure additional connection parameters for RIM platform.
- Improved RIM connection string solving the issue of when the devices is subscribed to BIS.
- Geo-located Trend search based on Yahoo! Where On Earth ID.
- Bug fixes and replacement of some deprecated Twitter API's resources.

I am really glad to have one more version of this successful project released. In addition, I would also like to thank everybody that contributed with the project, reporting bugs and requesting new features through our Express Support.

I strongly recommend you to migrate to v1.8 right away. So, download it now from here. I also prepared some sample apps to help developers to understand how to integrate OAuth into their apps. Just click here and have fun.

See you in the next post...

10 comments:

Nizaqat Ali said...

I am testing your twitter sample application, in which authentication is completed by entering pin code.Is there any way to by pass pin code step.

i want to invoke twitter login page then after login successful onAuthorize method/function will call.

please guide me

Ernandes Mourão Júnior said...

Hi,

In this case, you should not use the out-of-band mode, which is activated by passing null for the url callback parameter.

To work like you expect, you need to define a callback url in your twitter app's page and then register a listener to receive notification about when the user is authenticated.

Please, read these links below and you will understand:

http://kenai.com/projects/twitterapime/pages/Home#AuthMethods

http://kenai.com/projects/twitterapime/pages/Home#AuthUser (from "Authenticate user with OAuth method")

Regards,

Nizaqat Ali said...

Hi,
According to your instructions, i run twitter sample application successfully. After login page callback url opened into browser but problem is that OAuthDialogListener (onAuthorize()method)did not execute.

Nizaqat Ali said...

Dear,

Please guide me how i modify OAuthDialogListener class in order to i can invoke method "triggerOnAuthorize()"?

Nizaqat Ali said...

Mr.Ernandes,

I do not want to disturb you. I am very sorry, i asked wrong question above.

According to your guide, i put callback URL instead of null value. After login successful, it jump to the callback url but did not trigger the onAuthorize() method.

Now at this stage what should i do.

Ernandes Mourão Júnior said...

Have you registered your listener object?

page.setOAuthListener(new OAuthDialogListener() {
public void onAuthorize(Token token) {
//grab the token and tweet from here.
}
));

Nizaqat Ali said...

Yes i registered listener.Twitter related code:
//************************************************
MyOAuthDialogWrapper page = new MyOAuthDialogWrapper(midlet);
page.setConsumerKey(this.CONSUMER_KEY);
page.setConsumerSecret(this.CONSUMER_SECRET);
page.setCallbackUrl("http://www.goodinside.org/");
page.setOAuthListener(new OAuthDialogListener() {
/**Callback when user authorizes the app to access the account.*/
public void onAuthorize(Token token) {
System.out.println("Authorized user");
}
/**Callback when user denies the app to access the account.*/
public void onAccessDenied(String message) {
System.out.println("user access denied");
}
/**Callback when any error happens during authentication.*/
public void onFail(String message, String description) {
System.out.println("user fail to authorize");
}
});
//*****************************************************************************
package utz.tracer.social.networks;

import com.twitterapime.xauth.ui.OAuthDialogListener;
import com.twitterapime.xauth.ui.OAuthDialogWrapper;

import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.midlet.MIDlet;

/**This class load the login page of twitter and override two methods of OAuthDialogWrapper class (loadUrl() & loadHTML())*/
public class MyOAuthDialogWrapper extends OAuthDialogWrapper
{
private MIDlet midlet;

/**Constructor*/
public MyOAuthDialogWrapper(MIDlet midlet, String consumerKey,String callBackUrl, String consumerSecret, OAuthDialogListener oauthListener)
{
super(consumerKey, consumerSecret, callBackUrl, oauthListener);

if (midlet == null) {
throw new IllegalArgumentException("MIDlet must not be null.");
}

setEnableCustomResultPages(true);
this.midlet = midlet;
}

public MyOAuthDialogWrapper(MIDlet midlet)
{
this(midlet, null, null, null,null);
}

/**Override method. It will browse twitter login URL.*/
protected void loadUrl(String url){
try{

boolean exit = this.midlet.platformRequest(url);
if (exit)
this.midlet.notifyDestroyed();
}
catch (ConnectionNotFoundException e) {
throw new IllegalArgumentException(e.getMessage());
}
}

/**Override method. It will browse callback url*/
public void setCallbackUrl(String callbackUrl){
super.setCallbackUrl(callbackUrl);
}

/**Override method. It will load the twitter login html content.*/
protected void loadHTML(String htmlContent){}
}
//******************************
Now guide me ,is it correct? thanks

Ernandes Mourão Júnior said...

You are not supposed to extend OAuthDialogWrapper class, but extend the subclasses specific for you platform. As I could see, you are working with Java ME, in this case, MIDletOAuthDialogWrapper is the one you should extend.

On the other hand, Java ME + OAuth have some constraints, and one of them is that onAuthorize() method is not called. None of OAuthDialogListener is, by the way.

Please, read this http://kenai.com/projects/twitterapime/pages/Home#AuthOOB.

Regards,

Nerd Progre said...

Great news. But this is just a lib or devs. What is a good END-USER Twitter app for J2ME phones that uses this library? Anyone? thanks in adavance.

FC

Eric Simmons said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

Best Recommended books for Spring framework

Java Interview Questions












Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Java Course in Chennai