2010-03-31 101 views
2

我刚刚发现的Facebook Connect on Blackberry一个伟大的样品由驿Y. Baskoro,黑莓 - Facebook的扩展权限

以下是对黑莓手机使用Facebook Connect短HOWTO。我创建了一个封装Facebook REST API的简单Facade,并为屏幕导航添加了“粗略”MVC方法。我已经使用8320模拟器在JDE 4.5上进行了测试。这仍在进行中,所有工作都是GPL。

它适用于阅读东西。

NB别忘了get Facebook App Key并将其设置在TestBB类中。

但现在我想在墙上张贴一些东西。所以我添加新的方法来FacebookFacade类使用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); 
} 

这将返回错误代码200,“用户未授权的应用程序来执行此操作”

首先我认为这是相关与Facebook的- >应用程序设置 - >额外的权限 - >发布的近期活动(一条线的故事)我的墙但即使检查,没有什么区别...

然后我发现这个post解释了有关这一问题extended permissions

反过来,这应该是固定的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(); 
} 

遗憾的是它不工作。仍然错误代码200返回到stream.publish请求...

你有任何建议如何解决这个问题?

谢谢!

回答

2

我在我的网站上公布了更新的API(http://www.baskoro.web.id/facebook-connect-blackberry-HOWTO.html),这应该可以解决这个问题。请不要让我知道。

萨拉姆。干杯!

Eki

+0

谢谢,它的工作,它太棒了! – 2010-04-16 19:41:05

+0

嗨,即使我使用相同的baskaro代码,但起初我得到了无效的参数错误。在为LoginScreen构造函数添加代码后,我获得成功,但未重定向到其他页面。你能帮我解决吗?该页面只显示成功,没有别的。 – sunil 2010-06-12 10:03:09

+0

苏尼尔,这个问题已经解决。看看我的网站或直接访问Facebook的BlackBerry SDK项目网站(https://sourceforge.net/projects/facebook-bb-sdk) – Eki 2010-07-06 09:01:14