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
zakirhussain3654
Posts: 47
Registered: ‎03-09-2011
My Carrier: Airtel
Accepted Solution

Integration of Facebook and Twitter

Any one tell me how i integrate facebook and twitter in my app 

 

 provide your suggesstion as soon as possible 

Thanks & Regard
Zakir Hussain
Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Integration of Facebook and Twitter

you can use the search to find appropriate topics about that.

otherwise start with
http://us.blackberry.com/developers/started/facebook.jsp
and twitterME
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
zakirhussain3654
Posts: 47
Registered: ‎03-09-2011
My Carrier: Airtel

Re: Integration of Facebook and Twitter

[ Edited ]
public class Home extends UiApplication 
{
	public static void main(String[] args) 
	{
		Home app = new Home();
		app.enterEventDispatcher();
	}

	public Home() 
	{
		pushScreen(new TwitterAPIMERIMOauthSample());
	}

}




public class TwitterAPIMERIMOauthSample extends MainScreen 
{
	private final String CONSUMER_KEY = "";
	private final String CONSUMER_SECRET = "";
	private final String CALLBACK_URL = "";

	public TwitterAPIMERIMOauthSample() 
	{
		super(VERTICAL_SCROLL);
		setTitle("Twitter Demo");
		BrowserField browserField = new BrowserField();
		add(browserField);
		OAuthDialogWrapper pageWrapper = new BrowserFieldOAuthDialogWrapper(browserField);
		pageWrapper.setConsumerKey(CONSUMER_KEY);
		pageWrapper.setConsumerSecret(CONSUMER_SECRET);
		pageWrapper.setCallbackUrl(CALLBACK_URL);
		pageWrapper.login();
	}
}





public final class BrowserFieldOAuthDialogWrapper extends OAuthDialogWrapper
{
	private BrowserField browserField;
	public BrowserFieldOAuthDialogWrapper(BrowserField browserField,String consumerKey, String consumerSecret, String callbackUrl,OAuthDialogListener oauthListener) 
	{
		super(consumerKey, consumerSecret, callbackUrl, oauthListener);
		if (browserField == null) 
		{
			throw new IllegalArgumentException("BrowserField must not be null.");
		}
		this.browserField = browserField;
		this.browserField.addListener(new BrowserFieldListenerOAuth());
	}
	
	public BrowserFieldOAuthDialogWrapper(BrowserField browserField) 
	{
		this(browserField, null, null, null, null);
	}

	protected void loadUrl(String url) 
	{
		browserField.requestContent(url);
		System.out.println("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"+ url);
	}
	
	protected void loadHTML(String htmlContent) 
	{
		browserField.displayContent(htmlContent, callbackUrl);
		System.out.println("22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"+ htmlContent);
	}
	
	private class BrowserFieldListenerOAuth extends BrowserFieldListener 
	{
		public void documentLoaded(BrowserField browserField, Document document)throws Exception 
			{
				trackUrl(browserField.getDocumentUrl());
				System.out.println("33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"+ browserField.getDocumentUrl());
			}
	}
}

 

Hii All,

 

I done twitter integration in blackberry  but i got two times login 

 

Can any one help me how i remove two times login problem

 

Here above is my code for twitter integration

 

 

Thanks & Regard
Zakir Hussain
Please use plain text.
Developer
pankajace12
Posts: 192
Registered: ‎04-30-2011
My Carrier: Airtel

Re: Integration of Facebook and Twitter

[ Edited ]

Hi Zakir,

 

Do one thing, Here after login you need to Store the Token value. So that you may work on this condition for next time.

  

you can use StoreToken Class to store the value of tokens.
 

public void onAuthorize(final Token token) {

			final Token myToken = token;
                          public StoreToken _tokenValue;
			_tokenValue = StoreToken.fetch();
			_tokenValue.token = myToken.getToken();
			_tokenValue.secret = myToken.getSecret();
			_tokenValue.userId = myToken.getUserId();
			_tokenValue.username = myToken.getUsername();
			_tokenValue.save();

			UiApplication.getUiApplication().invokeLater( new Runnable() {

				public void run() {
					deleteAll();
					Credential c = new Credential(CONSUMER_KEY,	CONSUMER_SECRET, myToken);
					TweetToFriend tw = new TweetToFriend();
					String message="";
					boolean done=false;
					done=tw.doTweet(message, c);
					if(done == true)
					{
						Dialog.alert( "Tweet succusfully..." );
						close();	
					}
				}
			});

 

After storing this token value. Give condition for next time.  like this:

 

if(_tokenValue.token.equalsIgnoreCase("nothing"))
				{
					showAuthBrowserScreen.doAuth( null );
					UiApplication.getUiApplication().pushScreen(showAuthBrowserScreen);
				}
				else
				{ 
doTweet();
this will directly tweet without asking the login.

 

 


Please use plain text.
Contributor
praveennagsethiya
Posts: 20
Registered: ‎05-21-2012
My Carrier: NA

Re: layout the image button

sir how to set layout the image button in blackberry. means put button in a appropriate position.

Please use plain text.
Developer
pankajace12
Posts: 192
Registered: ‎04-30-2011
My Carrier: Airtel

Re: layout the image button

Hi Praveen

 

	VerticalFieldManager _vfm = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL)
		{
			protected void sublayout( int maxWidth, int maxHeight)
			{
				layoutChild(_lblEmail, getPreferredWidth(), getPreferredHeight());
				setPositionChild(_lblEmail,50,50);

				layoutChild(_image, getPreferredWidth(), getPreferredHeight());
				setPositionChild(_image,50,100);

				super.setExtent(SizeSpec.uiWidth,SizeSpec.uiHeight);

			}
		};

 

Thanks

Please use plain text.
Contributor
praveennagsethiya
Posts: 20
Registered: ‎05-21-2012
My Carrier: NA

Re: layout the image button

sir i want image button(Next-Previous) is always on bottom for all simulator like 9550,9700......etc.then what should i do?

sir plz its very urgent

 code here:-

////////////////////////////Main screen//////////////////////////

import net.rim.device.api.ui.UiApplication;


public class Main extends UiApplication {

    Main uiMainObj = this;

    public static void main(String args[]) {
        Main mn = new Main();
        mn.enterEventDispatcher();
    }

    public Main() {
        UiApplication.getUiApplication().invokeAndWait(new Runnable() {
            public void run() {
        //new SplashScreen(uiMainObj, new Screen_1());
                pushScreen(new SplashScreen());
        }
        });
        
        
    }
}

 

 

//////////////////////////////////////first screen////////////////////////////////

 

 

import java.util.Hashtable;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
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.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class Screen_1 extends MainScreen implements FieldChangeListener {

    private EmbossedButtonField btnPrev;
    private EmbossedButtonField btnNext;
//    private Bitmap bitmap;
//    private CustomLabel lblText;
    
    public Screen_1(){
        super(NO_VERTICAL_SCROLL);
        //setTitle("Recharge Digital Company Ltd.");
    //    bitmap = ScreenConstant.FIFTINSCREEN;
        buildUi();
    }

    private void buildUi() {
        // TODO Auto-generated method stub
        BGVFM vfmBase = new BGVFM(NO_VERTICAL_SCROLL| NO_VERTICAL_SCROLLBAR | USE_ALL_HEIGHT);
        VerticalFieldManager vfmmain = new VerticalFieldManager(NO_VERTICAL_SCROLL | Manager.USE_ALL_HEIGHT | USE_ALL_WIDTH);
        this.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(ScreenConstant.FIRSTSCREEN));
        HorizontalFieldManager hfmButton = new HorizontalFieldManager();
        
        int prt = (int)(20*Display.getWidth()/480);
        int nlt = (int)(280*Display.getWidth()/480);
        
          
        btnPrev = new EmbossedButtonField(MessageConstant.BTN_PREV, ButtonField.CONSUME_CLICK){
            protected boolean navigationClick(int status, int time) {                        
                fieldChangeNotify( 100 );
                return true;
            }
        };
        btnPrev.setMargin(0, 0, 0, prt);
        btnPrev.setChangeListener(this);

        btnNext = new EmbossedButtonField(MessageConstant.BTV_NEXT, ButtonField.CONSUME_CLICK){
            protected boolean navigationClick(int status, int time) {                        
                fieldChangeNotify( 100 );
                return true;
            }
        };
        
        btnNext.setMargin(0, 0, 0,nlt);
        btnNext.setChangeListener(this);
        
        hfmButton.add(btnPrev);
        hfmButton.add(btnNext);
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
        vfmmain.add(new LabelField());
//        vfmmain.add(bannerAd);
//        vfmmain.add(new LabelField());
        vfmmain.add(hfmButton);
        vfmBase.add(vfmmain);
//        vfmBase.add(vfmmain);
        this.add(vfmBase);        
    }

    protected boolean onSavePrompt() {
        return true;
    }
    
    protected boolean keyChar(char key, int status, int time) {
        // Intercept the ENTER key.
         if(key == Characters.ESCAPE)
        {
             Dialog dlgLogout = new Dialog(Dialog.D_YES_NO,MessageConstant.CLOSEAPP,Dialog.NO,Bitmap.getPredefinedBitmap(Bitmap.QUESTION),Manager.FOCUSABLE);
                int reponse = dlgLogout.doModal();
                if(reponse==Dialog.YES){
                    System.exit(0);
                }
            
            return true;
        }
        return super.keyChar(key, status, time);
    }
    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        if (context == 100) {
            if(field.getOriginal() == btnPrev){
                /*Dialog.alert("Application going to close !");
                System.exit(0);*/
                Dialog dlgLogout = new Dialog(Dialog.D_YES_NO,MessageConstant.CLOSEAPP,Dialog.NO,Bitmap.getPredefinedBitmap(Bitmap.QUESTION),Manager.FOCUSABLE);
                int reponse = dlgLogout.doModal();
                if(reponse==Dialog.YES){
                    System.exit(0);
                }
            }if(field.getOriginal() == btnNext){
            //Dialog.alert("Next Button is pressed");
            UiApplication.getUiApplication().pushScreen(new Screen_2 ());
            }
        }
    }
}

 

 

    

Please use plain text.
Contributor
praveennagsethiya
Posts: 20
Registered: ‎05-21-2012
My Carrier: NA

Re: layout the image button

sir plz give me your Email-id then i send my full code to you.sir please.......

sir if you are solve my 2-3 problem then my project is complete. please help me.sir i am very thankful to you.

 no buddy help me accept  you.thankyou

Please use plain text.
Contributor
zakirhussain3654
Posts: 47
Registered: ‎03-09-2011
My Carrier: Airtel

Re: layout the image button

[ Edited ]

Hii praveen,

 

If u want a button at bottom then u can add button in "setStatus(new Button("Your Button Name"))" the u can  see button at bottom 

i can but an example for  you - ::


vfmStatus = new VerticalFieldManager(VerticalFieldManager.NO_VERTICAL_SCROLL| VerticalFieldManager.NO_VERTICAL_SCROLLBAR| VerticalFieldManager.USE_ALL_WIDTH);
hfmSattus = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER| HorizontalFieldManager.FIELD_VCENTER);
hfmSattus.add(new Button("Click On Me"));
vfmStatus.add(hfmSattus);

setStatus(vfmStatus);

 

On the above example i added a button in horizontalfiledmanager and this horizontafiledmanger added in verticafiledmanger and  finally this vertcalfieldmanger added in setStatus .

Thanks & Regard
Zakir Hussain
Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: layout the image button

please open an own thread for your question.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.