Help with Blackberry and Twitter integration
Please Login to Remove!
Im developing an application that should to be able to share contents to twitter, and i cant get OAuth to work.
Im trying with the library twitter_api_me-1.8.jar and the example TwitterAPIME-RIM-OAuthSample.
The problem i think is in the callback, because im able to open the twitter login page and login, but after that i dont know how to get back to the application, and the method public void onAuthorize(Token token) is never invoked.
Ive been searching this in google and i found that a lot of people had the same problem, but unfortunately i didnt find any solution.
Thanks to all.
Here is my source code:
package com.twitterapime.oauth;
import impl.rim.com.twitterapime.xauth.ui.BrowserContentM anagerOAuthDialogWrapper;
import net.rim.device.api.browser.field.BrowserContentMan ager;
import net.rim.device.api.browser.field.RenderingOptions;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import com.twitterapime.rest.Credential;
import com.twitterapime.rest.TweetER;
import com.twitterapime.rest.UserAccountManager;
import com.twitterapime.search.Tweet;
import com.twitterapime.xauth.Token;
import com.twitterapime.xauth.ui.OAuthDialogListener;
import com.twitterapime.xauth.ui.OAuthDialogWrapper;
public class TwitterAPIMERIMOauthSample extends UiApplication {
/**
* @param args
*/
public static void main(String[] args) {
TwitterAPIMERIMOauthSample app = new TwitterAPIMERIMOauthSample();
app.enterEventDispatcher();
}
/**
*
*/
public TwitterAPIMERIMOauthSample() {
pushScreen(new BrowserFieldScreen());
}
}
/**
*/
class BrowserFieldScreen extends MainScreen{
/**
*
*/
private final String CONSUMER_KEY = "<consumer key>";
/**
*
*/
private final String CONSUMER_SECRET = "<consumer secret>";
/**
*
*/
public static final String CALLBACK_URL= "";
/**
*
*/
public BrowserFieldScreen() {
setTitle("Twitter API ME - OAuth");
BrowserContentManager browserMngr = new BrowserContentManager(0);
RenderingOptions rendOptions = browserMngr.getRenderingSession().getRenderingOpti ons();
rendOptions.setProperty(
RenderingOptions.CORE_OPTIONS_GUID,
RenderingOptions.SHOW_IMAGES_IN_HTML,
false);
//
add(browserMngr);
//
OAuthDialogWrapper pageWrapper =
new BrowserContentManagerOAuthDialogWrapper(browserMng r);
//
pageWrapper.setConsumerKey(CONSUMER_KEY);
pageWrapper.setConsumerSecret(CONSUMER_SECRET);
pageWrapper.setCallbackUrl(CALLBACK_URL);
pageWrapper.setOAuthListener(new OAuthDialogListener() {
public void onAuthorize(Token token) {
Credential c = new Credential(CONSUMER_KEY, CONSUMER_SECRET, token);
UserAccountManager uam = UserAccountManager.getInstance(c);
//
try {
if (uam.verifyCredential()) {
TweetER.getInstance(uam).post(new Tweet("test: " + System.currentTimeMillis()));
//
System.out.println("Tweet posted!");
}
} catch (Exception e) {
System.out.println("Error by posting tweet.");
}
}
/**
* @see com.twitterapime.xauth.ui.OAuthDialogListener#onAc cessDenied(java.lang.String)
*/
public void onAccessDenied(String message) {
System.out.println("Access denied!");
}
/**
* @see com.twitterapime.xauth.ui.OAuthDialogListener#onFa il(java.lang.String,
* java.lang.String)
*/
public void onFail(String error, String message) {
System.out.println("Error by authenticating user!");
}
});
//
pageWrapper.login();
}
}
Last edited by kelospario; 01-26-2012 at 02:14 PM..
|