如何使用黑莓 API 访问 facebook 或 twitter?

发布于 2024-08-03 16:25:39 字数 275 浏览 8 评论 0原文

我是使用黑莓 API 进行此类社交网络应用程序集成的新手。

我想开发这样一种应用程序,可以使用可用的黑莓 API 来集成 facebook 或 twitter 社交网站。

如何使用黑莓API访问facebook? 是否有任何可用的 facebook 网络服务,黑莓 api 可以在其上工作和访问它? 是否有任何具有完整源代码的应用程序可以使用黑莓 API 访问 facebook?

如果有人有任何解决方案或任何有用的链接或任何代码片段,我们将不胜感激。:)

谢谢, 米沙尔

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云淡风轻 2024-08-10 16:25:39

Facebook 提供了一个基于 Web 服务的 API,您可以使用 - 他们在这里提供相关信息:

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

我强烈建议使用 Sun Java Wireless Toolkit(适用于 CLDC 的 Sun Java Wireless Toolkit 2.5.2_01 可在此处获取:SJW Toolkit) - 安装后使用实用程序应用程序,然后使用“存根生成器” - 它将为所有内容创建 J2ME 类和存根然后您可以将其引入 BlackBerry 项目中的 Web 服务调用。我已经使用它从 BlackBerry 调用 Web 服务,并且它比创建您自己的 Web 服务调用包装器要容易得多。一切都将是强类型的,并且任何所需的对象和类都将为您创建。

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.

北笙凉宸 2024-08-10 16:25:39

BlackBerry FaceBook Connect

请参阅 Eki Y. Baskoro 提供的代码示例:Facebook Connect on黑莓

以下是有关在 Blackberry 上使用 Facebook Connect 的简短 HOWTO。我创建了一个简单的 Facade,封装了 Facebook REST API,并添加了用于屏幕导航的“粗略”MVC 方法。我已经使用 8320 模拟器在 JDE 4.5 上进行了测试。这仍在进行中,所有工作都是 GPL 的。

BlackBerry Twitter Connect

说到 twitter,有一个 twitter api 和开源 j2me 客户端 - jibjib 来看看。
发布状态示例:

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

更新

适用于 RIM 的 Twitter API ME lib v.1.8 可在 基奈项目

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

冷默言语 2024-08-10 16:25:39

Twitter 基本身份验证方法从今天开始已弃用。
您现在必须使用 OAuth ...

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

独自←快乐 2024-08-10 16:25:39

要使用本机应用程序从黑莓连接到 Facebook,您可以使用适用于黑莓的 Facebook sdk。您可以从 github.com 下载。搜索 Facebook sdk。它还附带一些示例,清楚地演示了 Facebook api 的用法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文