我剛剛發現的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請求...
你有任何建議如何解決這個問題?
謝謝!
謝謝,它的工作,它太棒了! – 2010-04-16 19:41:05
嗨,即使我使用相同的baskaro代碼,但起初我得到了無效的參數錯誤。在爲LoginScreen構造函數添加代碼後,我獲得成功,但未重定向到其他頁面。你能幫我解決嗎?該頁面只顯示成功,沒有別的。 – sunil 2010-06-12 10:03:09
蘇尼爾,這個問題已經解決。看看我的網站或直接訪問Facebook的BlackBerry SDK項目網站(https://sourceforge.net/projects/facebook-bb-sdk) – Eki 2010-07-06 09:01:14