我正在开发一个黑莓原生应用程序,它使用Facebook和Twitter共享消息等功能。在我看到我发现可以使用Facebook SDK以便与Facebook服务集成后。
我已从此链接https://sourceforge.net/projects/facebook-bb-sdk/
下载了SDK我已按照README pdf文件中解释的步骤进行了解释,该文件与SDK捆绑在一起。我已按照以下步骤进行操作
第1步:获取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);
第2步:检索当前用户
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
}
});
第3步:发布用户状态。
user.publishStatus("Hello world!");
但是,它给出了IOException并且没有任何反应。我相信很多人早些时候做过类似的事情。我正在寻找一个源解释与Facebook服务集成的一步一步的过程。
答案 0 :(得分: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());
}
}
}