views:

3039

answers:

6

Hi,

I am newbie for such kind of social networking Application integration using blackberry API.

i want to develope such kind of application which can use the facebook or twitter social networking site integration using available blackberry api.

how to access the faceBook using blackberry API? Is there any webservice available of facebook on which blackberry api can work and access it? is there any application exist with whole source code for accessing the facebook using the blackberry api?

if anybody has any solution or any useful link or any code snippet,which would be appreciated.:)

Thanks, Mishal

+5  A: 

Facebook offers a webservice-based API that you can use - they provide information about it here:

http://wiki.developers.facebook.com/index.php/Platform_Basics

I would strongly recommend using the Sun Java Wireless Toolkit (Sun Java Wireless Toolkit 2.5.2_01 for CLDC available here: SJW Toolkit) - use the Utilities application when installed and then the "Stub Generator" - it will create J2ME classes and stubs for all web service calls that you can then bring into your BlackBerry project. I have used this without fail to call web services from the BlackBerry and it is much easier than creating your own web service call wrappers. Everything will be strong typed and any required objects and classes will all be created for you.

JustinD
A: 

hai justin,

can u be more explanative.

thanks, Kamala

kamala
+2  A: 

BlackBerry FaceBook Connect

See code sample provided by Eki Y. Baskoro: Facebook Connect on Blackberry

The following is a short HOWTO on using Facebook Connect on Blackberry. I created a simple Facade encapsulating the Facebook REST API as well as added 'rough' MVC approach for screen navigation. I have tested on JDE 4.5 using 8320 simulator. This is still work in progress and all work is GPLed.

BlackBerry Twitter Connect

And talking about twitter, there is a twitter api and opensource j2me client - jibjib to look at.
Sample to post status:

 class Scr extends MainScreen implements FieldChangeListener {
    BasicEditField musername;
    BasicEditField mPassword;
    BasicEditField mStatus;
    ButtonField mUpdateStatus;

    public Scr() {
        add(musername = new BasicEditField("username: ", ""));
        add(mPassword = new BasicEditField("password: ", ""));
        add(mStatus = new BasicEditField("status: ", ""));
        mUpdateStatus = new ButtonField(ButtonField.CONSUME_CLICK);
        mUpdateStatus.setLabel("update status");
        mUpdateStatus.setChangeListener(this);
        add(mUpdateStatus);
    }

    public void fieldChanged(Field field, int context) {
        if (mUpdateStatus == field) {
            String username = musername.getText().trim();
            String password = mPassword.getText().trim();
            String status = mStatus.getText().trim();
            updateStatus(username, password, status);
        } else {

        }
    }

    void updateStatus(String username, String password, String status) {
        String response = "";
        try {
            String query = "status=" + urlEncode(status);
            String len = String.valueOf(query.length());
            SocketConnection hc = (SocketConnection) Connector
                    .open("socket://twitter.com:80");
            DataOutputStream dout = 
                new DataOutputStream(hc.openOutputStream());
            DataInputStream din = new DataInputStream(hc.openInputStream());
            String userPass = username + ":" + password;
            byte[] encoded = Base64OutputStream.encode(userPass.getBytes(), 0,
                    userPass.length(), false, false);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            String request = "POST /statuses/update.json HTTP/1.1\r\n"
                    + "Host: twitter.com:80\r\n"
                    + "User-Agent: curl/7.18.0 (i486-pc-linux-gnu) " +
                            "libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 " +
                            "libidn/1.1\r\n"
                    + "Accept: */*\r\n"
                    + "Content-Type: application/x-www-form-urlencoded\r\n"
                    + "Content-Length: " + len + "\r\nAuthorization: Basic "
                    + new String(encoded) + "\r\n\r\n";
            bos.write(request.getBytes());
            bos.write(query.getBytes());
            dout.write(bos.toByteArray());
            dout.flush();
            dout.close();
            byte[] bs = new byte[900];
            din.readFully(bs);
            bos = new ByteArrayOutputStream();
            bos.write(bs);
            din.close();
            hc.close();
            response = bos.toString();
        } catch (Exception ex) {
            System.out.println(ex.getMessage()+" "+response);
        }
    }

    public static String urlEncode(String s) {
        if (s != null) {
            try {
                s = new String(s.getBytes("UTF-8"), "ISO-8859-1");
            } catch (UnsupportedEncodingException e) {
            }
            StringBuffer tmp = new StringBuffer();
            try {
                for (int i = 0; i < s.length(); i++) {
                    int b = (int) s.charAt(i);
                    if ((b >= 0x30 && b <= 0x39) || (b >= 0x41 && b <= 0x5A)
                            || (b >= 0x61 && b <= 0x7A)) {
                        tmp.append((char) b);
                    } else if (b == 0x20) {
                        tmp.append("+");
                    } else {
                        tmp.append("%");
                        if (b <= 0xf) {
                            tmp.append("0");
                        }
                        tmp.append(Integer.toHexString(b));
                    }
                }
            } catch (Exception e) {
            }
            return tmp.toString();
        }
        return null;
    }
}
Max Gontar
A: 

Hi Eki,

I have gone through with all your posts in http://www.baskoro.web.id/facebook-connect-blackberry-HOWTO.html and as well as your replies in blackberry support forum.

Yea that is very great stuff you have mentioned.

Can you please send me the REQUEST URL for facebook as you have given in above twitter connect example. like >> String request = "POST....???

Waiting for your kind response.

Thanks, Rakesh Saytode

rakesh saytode
A: 

hi i have seen your code for twitter. can u please tell me how to get the friends list in useraccount i think i have to use Get method but i dont know how to use that can u plz give me the code to get the list of Friends.

and i got struck at

byte[] bs = new byte[900]; din.readFully(bs); bos = new ByteArrayOutputStream();

my simulator got struct at this line.. please help me.

yakub
A: 

Twitter Basic Auth method is deprecated starting today. You must now use OAuth ...

Mike