0

我正在开发一个黑莓本机应用程序,它使用 Facebook 和 twitter 消息共享等功能。经过仔细研究,我发现我可以使用 Facebook SDK 来与 Facebook 服务集成。

我已经从这个链接下载了 SDK https://sourceforge.net/projects/facebook-bb-sdk/

我已按照与 SDK 捆绑在一起的 README pdf 文件中说明的步骤进行操作。我已按照以下步骤

Step1:获取 Facebook 门面实例

String NEXT_URL = "http://www.facebook.com/connect/login_success.html"; 
String APPLICATION_ID = "15355516805e272"; // my app id
String APPLICATION_SECRET = "354f91a79c8fe5a8de9d65b55ef9aada"; // my app secret key 
String[] PERMISSIONS = Facebook.Permissions.USER_DATA_PERMISSIONS; 

ApplicationSettings as = new ApplicationSettings(NEXT_URL, APPLICATION_ID, 
APPLICATION_SECRET, PERMISSIONS); 
Facebook fb = Facebook.getInstance(as);

Step2:检索当前用户

fb.getCurrentUser(new BasicAsyncCallback() { 

        public void onComplete(com.blackberry.facebook.inf.Object[] 
objects, final java.lang.Object state) { 
          user = (User) objects[0]; 
          // do whatever you want 
        } 

        public void onException(final Exception e, final 
java.lang.Object state) { 
          e.printStackTrace(); 
          // do whatever you want 
        } 

});

Step3:发布用户状态。

user.publishStatus("Hello world!"); 

但是,它给出了 IOException 并且没有任何反应。我相信很多人之前都做过类似的事情。我正在寻找一个解释与 Facebook 服务集成的逐步过程的来源。

4

2 回答 2

0

我最近在我的基于 Blackberry 7 的应用程序中实现了Facebook 和 Twitter集成。我发现了什么,Facebook API 有错误,甚至是 Beta 版。请尝试以下 API:FacebookAPIMeTwitterAPIMe。如果您在实现此 API 时遇到任何问题,我会为您提供帮助。两者都易于使用且易于与您的应用程序集成。两者都包含示例应用程序,因此您还可以查看该 API 的演示。

于 2013-01-18T11:50:29.137 回答
0

这段代码对我有用。它显示了如何获取当前用户和发布状态

public class FacebookHelper {

private final String NEXT_URL = "http://www.facebook.com/connect/login_success.html";
private final String APPLICATION_ID = "123456789";
private final String APPLICATION_SECRET = "123456789123456789123456789123456789";
String[] PERMISSIONS = Facebook.Permissions.PUBLISHING_PERMISSIONS;
User user;
Facebook fb;
ApplicationSettings as = new ApplicationSettings(NEXT_URL, APPLICATION_ID,
        APPLICATION_SECRET, PERMISSIONS);

public  FacebookHelper() {
    fb = Facebook.getInstance(as);
}

public void publishContent(final String content) {
    try {
        fb.getCurrentUser(new BasicAsyncCallback() {
            public void onComplete(
                    com.blackberry.facebook.inf.Object[] objects,
                    final java.lang.Object state) {
                user = (User) objects[0];
                user.publishStatus(content);  
            }

            public void onException(final Exception e,
                    final java.lang.Object state) { 
                System.out.println("Exception inside BasicAsyncCallback " + e.toString()
                        + " , " + e.getMessage());
            }
        });
    } catch (Exception e) {
        System.out.println("Exception in publishContent " + e.toString() + " , "
                + e.getMessage());
    }
}
}
于 2012-10-19T08:44:11.937 回答