views:

552

answers:

2

Hi!

I've just found a great sample of Facebook Connect on Blackberry by Eki Y. Baskoro,

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.

It works great for reading stuff.

NB Don't forget to get Facebook App Key and set it in TestBB class.

But now I want to post something on my wall. So I've add new method to FacebookFacade class using Stream.publish API:

 /***
 * Publishes message to the stream.
 * @param message - message that will appear on the facebook stream
 * @param targetId - The ID of the user, Page, group, or event where 
 *     you are publishing the content.
 */
public void streamPublish(String message, String targetId)
{
    Hashtable arguments = new Hashtable();
    arguments.put("method", "stream.publish");
    arguments.put("message", message);
    arguments.put("target_id", targetId);
    try {
        JSONObject result = new JSONObject(
        int new JSONTokener(sendRequest(arguments)));            
        int errorCode = result.getInt("error_code");
        if (errorCode != 0) System.out.println("Error Code: "+errorCode);
    } catch (Exception e) {
        System.out.println(e);
    }
}

 /***
 * Publishes message on current user wall.
 * @param message - message that will appear on the facebook stream
 */
public void postOnTheWall(String message)
{
    String targetId = String.valueOf(getLoggedInUserId()); 
    streamPublish(message, targetId);
}

This will return Error code 200, "The user hasn't authorized the application to perform this action"

First I thought it's related with Facebook -> Application Settings -> Additional Permissions -> Publish recent activity (one line stories) to my wall but even checked, no difference...

Then I've found this post explains that issue related with extended permissions.

This in turn should be fixed by modifying url a little in LoginScreen class :

public LoginScreen(FacebookFacade facebookFacade) {
    this.facebookFacade = facebookFacade;

    StringBuffer data = new StringBuffer();
    data.append("api_key=" + facebookFacade.getApplicationKey());
    data.append("&connect_display=popup");
    data.append("&v=1.0");
    //revomed
    //data.append("&next=http://www.facebook.com/connect/login_success.html");
    //added     
    data.append("&next=http://www.facebook.com/connect/prompt_permissions.php?" +
    "api_key="+facebookFacade.getApplicationKey()+"&display=popup&v=1.0"+
    "&next=http://www.facebook.com/connect/login_success.html?"+
    "xxRESULTTOKENxx&fbconnect=true" +
    "&ext_perm=read_stream,publish_stream,offline_access");     
data.append("&cancel_url=http://www.facebook.com/connect/login_failure.html");
    data.append("&fbconnect=true");
    data.append("&return_session=true");
    (new FetchThread("http://m.facebook.com/login.php?" 
            + data.toString())).start();
}

Unfortunately it's not working. Still Error Code 200 in return to stream.publish request...

Do you have any suggestions how to resolve this?

Thank you!

A: 

I am also facing the same problem. Does anyone have the solution?

shimul
Please don't use "Post Your Answer" button for questions. use "add comment" link below post instead. please delete your post, thanks ;)
Max Gontar
+1  A: 

Hello, I have posted the updated API on my website (http://www.baskoro.web.id/facebook-connect-blackberry-HOWTO.html) and this should solve this issue. Please let me know otherwise.

Salam. Cheers!

Eki

Eki
Thank you, it's working and it's great!
Max Gontar
Hi, even I am using the same baskaro code but at first I was getting the invalid parameter error. After putting your code for LoginScreen constructor now I get Success but it is not redirected to another page. Can you please help me out in this? The page just displays success and nothing else.
sunil
Sunil, this issue has been resolved. Have a look at my website or go to the Facebook BlackBerry SDK project website directly (https://sourceforge.net/projects/facebook-bb-sdk)
Eki