Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
nidhicdn
Posts: 45
Registered: ‎10-25-2012
My Device: 8520
My Carrier: ss
Accepted Solution

unable to post using twitter sdk

[ Edited ]

I am unable to post using twitter sdk , My credential is unable to veriify every time. please test my code where I am wrong

 

package mypackage;

import impl.rim.com.twitterapime.xauth.ui.BrowserFieldOAuthDialogWrapper;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
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 TwitterScreen11 extends MainScreen  {

    private final String CONSUMER_KEY ="NNIMJ7Jwy3fbYKCuSt0eA";
    private final String CONSUMER_SECRET ="XVkHEu8G6Ne52Rpujlwu8qOkB5jYfhFSNTeurMBCt8";
    private final String CALLBACK_URL ="http://www.google.co.in";//"http://twitterapp://connect";
    private LabelField _labelStutus;
    private OAuthDialogWrapper pageWrapper = null;
    //    public StoreToken _tokenValue;
    ShowAuthBrowser showAuthBrowserScreen;

    public TwitterScreen11()
    {
        setTitle("Twitter Integration using OAuth");

        showAuthBrowserScreen = new ShowAuthBrowser();

        add ( new ButtonField("Tweet" ) {
            protected boolean navigationUnclick(int status, int time) {
                showAuthBrowserScreen.doAuth( null );
                UiApplication.getUiApplication().pushScreen(showAuthBrowserScreen);

                return true;
            }
        });
    }


    public boolean doTweet( String message, Credential c )
    {
        boolean done=false;
        UserAccountManager uam = UserAccountManager.getInstance(c);
        try
        {
            if (uam.verifyCredential())
            {
                TweetER.getInstance(uam).post(new Tweet( message ));
                done = true;
            }
        }
        catch (Exception e)
        {
            System.out.println("Error by posting tweet."+e.getMessage());
        }
        return done;
    }

    class ShowAuthBrowser extends MainScreen implements OAuthDialogListener
    {
        BrowserField b = new BrowserField();

        public ShowAuthBrowser()
        {    
            _labelStutus = new LabelField("Your app is being authorize." );
            add(_labelStutus );
            add(b);
            pageWrapper = new BrowserFieldOAuthDialogWrapper(b,CONSUMER_KEY,CONSUMER_SECRET,CALLBACK_URL,this);
            pageWrapper.setOAuthListener(this);

        }
        public void doAuth( String pin )
        {
            try
            {
                if ( pin == null )
                {
                    pageWrapper.login();
                }
                else
                {
                    this.deleteAll();
                    add(b);
                    pageWrapper.login( pin );
                }

            }
            catch ( Exception e )
            {
                final String message = "Error loggin Twitter: " + e.getMessage();
                Dialog.alert( message );

            }            
        }


        public void onAccessDenied(String response ) {
            Dialog.alert("Access denied");
            System.out.println("Access denied! -> " + response );
            updateScreenLog( "Acceso denegado! -> " + response );

        }

        public void onAuthorize(final Token token) {

            final Token myToken = token;

            Credential c = new Credential(CONSUMER_KEY,    CONSUMER_SECRET,token);
            String message="888 here";
            boolean done=false;
            done=doTweet(message, c);
            if(done == true)
            {
                UiApplication.getUiApplication().invokeLater( new Runnable() {
                    public void run() {
                        UiApplication.getUiApplication().pushScreen(new MyScreen("Tweet succusfully"));
                    }
                });
            }else{
                UiApplication.getUiApplication().invokeLater( new Runnable() {
                    public void run() {
                        UiApplication.getUiApplication().pushScreen(new MyScreen("unable to tweet"));
                    }
                });

            }
            //                }
            //            });

        }

        public void onFail(String arg0, String arg1) {
            Dialog.alert("fail Authroise");
            updateScreenLog("Error authenticating user! -> " + arg0 + ", " + arg1);

        }
    }


    private void updateScreenLog( final String message )
    {
        UiApplication.getUiApplication().invokeLater( new Runnable() {

            public void run() {
                _labelStutus.setText( message );                
            }
        });
    }



    public boolean onClose() {
        close();
        return true;
    }

}

 

Plz help

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: unable to post using twitter sdk

hi nidhicdn,
i have done the Twitter integration. you can download the demo here http://supportforums.blackberry.com/t5/Java-Development/Twitter-integration-exception/td-p/2472381/p....  but read this thread from starting.

Please use plain text.
Contributor
nidhicdn
Posts: 45
Registered: ‎10-25-2012
My Device: 8520
My Carrier: ss

Re: unable to post using twitter sdk

[ Edited ]

I am running the demo application . Twitter login working properly but If I post message on twitter then first it check our credentials . My credential is unable to verified. And if we run directly post method withoud verifuedcredential() method then it is giving me use is not verified. :smileysad:

Please use plain text.
Contributor
nidhicdn
Posts: 45
Registered: ‎10-25-2012
My Device: 8520
My Carrier: ss

Re: unable to post using twitter sdk

Thanks your post is really helpfull. My issue resolved , This is the problem of twitter1.8 sdk , user credential is unable to verified. But in twitter 1.9 sdk  it is working properly. :smileyhappy:

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: unable to post using twitter sdk

u r welcome :smileyhappy:
Please use plain text.