Facebook oAuth implementation for blackberry

我怕爱的太早我们不能终老 提交于 2019-12-12 05:25:20

问题


I am working on a blackberry native application, which uses the features like Facebook and twitter sharing of messages. After goggling I found that I could make use of Facebook SDK in order to integrate with Facebook service.

I have downloaded the SDK from this link https://sourceforge.net/projects/facebook-bb-sdk/

I have followed the steps that are being explained in the README pdf file, which was bundled with SDK. I have followed the below steps

Step1: Getting Facebook façade instance

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: Retrieving current user

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: Publish user status.

user.publishStatus("Hello world!"); 

But, it gives IOException and nothing happens. I am sure many people have done similar things earlier. I am looking for a source explains step by step process of integrating with Facebook service.


回答1:


This code works for me. it shows how to get the current user and publish status

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



回答2:


I have recently implemented Facebook & Twitter Integration into my Blackberry 7 Based Application. What i Found with this, Facebook API having Errors and even it is in Beta version.Please try Following API: FacebookAPIMe and TwitterAPIMe. If you have any problem in implementing this APIs, i will help you.Both are Simple to Use and Easily integrated with your application.Both are Containing Example App so You can also view Demo of that API.



来源:https://stackoverflow.com/questions/12962248/facebook-oauth-implementation-for-blackberry

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