how to access facebook or twitter using blackberry API?

醉酒当歌 提交于 2019-12-18 11:56:16

问题


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


回答1:


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.




回答2:


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;
    }
}

UPDATE

Twitter API ME lib v.1.8 for RIM is available on Project Kenai




回答3:


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




回答4:


for connecting to Facebook from blackberry using native apps you can use Facebook sdk for blackberry. you can download from github.com. search for Facebook sdk. it will also comes with some samples which clearly demonstrates the usage of Facebook api.



来源:https://stackoverflow.com/questions/1340196/how-to-access-facebook-or-twitter-using-blackberry-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!