Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 107
Registered: ‎05-26-2011
My Device: Torch
My Carrier: Mobilink

Re: Facebook integration


public class FacebookIntegration {

    private static User user;
 

    private static String APPLICATION_ID = "";
    private static String APPLICATION_SECRET = "";

    private static String[] PERMISSIONS = Facebook.Permissions.ALL_PERMISSIONS;

    private static String[] prayerNames = { "Tahajud", "Fajr", "Shuruq", "Duhr", "Asr", "Maghrib",
            "Isha" };
    public static boolean posted = false;
    private static SharePopup _obj;
    public static boolean exception = false;
    static Facebook fb;
 
    private static StringBuffer accessToken;
    static {
        try {
            accessToken = new StringBuffer(new HttpClient().doGet(
                    "https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id="
                            + APPLICATION_ID + "&client_secret=" + APPLICATION_SECRET).toString()
                    .substring(13));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }// =
    }
    private static String NEXT_URL = "http://www.facebook.com/connect/login_success.html";

    // private static String NEXT_URL = "http://m.facebook.com/wall.php";

    public static boolean integrate(SharePopup obj) {

        _obj = obj;
        ApplicationSettings as = new ApplicationSettings(NEXT_URL, APPLICATION_ID,
                APPLICATION_SECRET, PERMISSIONS);

        fb = Facebook.getInstance(as);
        fb.setAccessToken(accessToken.toString());

        _obj.close();

        try {

            user = fb.getCurrentUser();

        } catch (FacebookException e1) {

            e1.printStackTrace();
            exception = true;
        }
        // if (!exception) {
        try {

            fb.getCurrentUser(new BasicAsyncCallback() {

                public void onComplete(com.blackberry.facebook.inf.Object[] objects,
                        final java.lang.Object state) {
                    FacebookIntegration.this.user = (User) objects[0];
                    Vector prayerTimes = (Vector) PrayerTimesDTO.getPrayerTimes();
                    String location = "Makkah";

                    SettingsDTO settings = (SettingsDTO) SettingsDTO.getSettings();

                    // if (settings != null &&
                    // settings.isGPS&&Constants.qualifiedCoordinates!=null){
                    // RecordStoreUtility rs =
                    // RecordStoreUtility.getRecordStore();
                    // rs.openRecord(RecordStoreUtility.CITY_GPS_REC_STORE);
                    // location = rs.readCityGps();
                    // rs.closeRecord();
                    // } else
                    if (Utility.readLocation()) {
                        RecordStoreUtility rs = RecordStoreUtility.getRecordStore();
                        rs.openRecord(RecordStoreUtility.CITY_NAME_REC_STORE);
                        location = rs.readCityName();
                        rs.closeRecord();

                    }

                    StringBuffer post = new StringBuffer("");
                    post.append("Location: " + location + " \n" + "Prayer Times:");
                    post.append("\n\n");
                    for (int i = 0; i < prayerTimes.size(); i++) {
                        post.append(FacebookIntegration.this.prayerNames[i] + ": "
                                + prayerTimes.elementAt(i));
                        post.append("\n\n");
                    }
                    post.append("\n\n");
                    user.publishStatus(post.toString());

                    posted = true;
                    // fb.setPermissions(postPermissions);
                    user.publishPost("stream.publish", "published through the Facebook API",
                            APPLICATION_SECRET, null, null, null, user.getId());
                    // try {
                    // fb.refreshAccessToken(true);
                    // } catch (FacebookException e) {
                    // // TODO Auto-generated catch block
                    // e.printStackTrace();
                    // }
                    // fb.logout(true);
                }

                public void onException(final Exception e, final java.lang.Object state) {
                    e.printStackTrace();
                    exception = true;
                    Logger.getInstance().logInformationEvent("fb exception " + e.toString());

                }
            });
        } catch (FacebookException e) {
            e.printStackTrace();
            exception = true;
        } catch (Exception e) {
            Logger.getInstance().logInformationEvent("fb exception " + e.toString());

        } finally {
          

        }

        return true;
    }

Highlighted
Contributor
Posts: 23
Registered: ‎10-17-2011
My Device: 9700
My Carrier: NA

Re: Facebook integration

HI , 

                 I am facing the same problem not getting the access token , if some one has , some sample code , can u please post it;s very urgent , bec this thing is already taking too much time , please reply as soon Smiley Sad .

 

Contributor
Posts: 14
Registered: ‎07-31-2012
My Device: 9790
My Carrier: airtel

Re: Facebook integration

Can you please send the full source code

Regular Contributor
Posts: 52
Registered: ‎07-04-2011
My Device: Bold-3
My Carrier: Developer

Re: Facebook integration

Hi,

Did you successfully integrate facebook integration in your application ?

I am asking because I have to to the same.

So,if you have done it can you please help me ?

 

Thanks