我正在嘗試將我的應用程序與社交網絡(Facebook和Twitter)集成。在Android佈局中獲取來自Facebook的提要
我想要爲例如用戶牆或公共牆上的接口,並將其發佈在我的佈局中,如滾動視圖或項目視圖(或任何sugestions !!!),這是解決了Twitter的,但我不能把這項工作放到臉書上。
我使用Graph API。
要做到在我的牆上後我創建的方法postTextOnMyWall:
public String postTextOnMyWall(String message) {
Log.d("Tests", "Testing graph API wall post");
try {
Bundle parameters = new Bundle();
parameters.putString("message", message);// key/value
this.mAsyncRunner.request("me/feed", parameters, "POST",
new WallPostTextRequestListener(), null);
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
public AsyncFacebookRunner getmAsyncRunner() {
return this.mAsyncRunner;
}
public void setmAsyncRunner(AsyncFacebookRunner mAsyncRunner) {
this.mAsyncRunner = mAsyncRunner;
}
}
這種方法爲收聽張貼短信,WallPostTextRequestListener
public class WallPostTextRequestListener implements RequestListener {
public void showToast(String message) {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
.show();
}
// called on successful completion of the Request
@Override
public void onComplete(String response, Object state) {
Log.d("WallPostTextRequestListener", "Got response: " + response);
String message = "<empty>";
try {
JSONObject json = Util.parseJson(response);
message = json.getString("message");
showToast("Mensagem escrita no teu mural facebook!: " + message);
} catch (JSONException e) {
Log.e("WallPostTextRequestListener", "JSON Error in response");
} catch (FacebookError e) {
Log.e("WallPostTextRequestListener",
"Facebook Error: " + e.getMessage());
}
final String text = "Mensagem: " + message;
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
// TODO Auto-generated method stub
}
// called if there is an error
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
而且他們我只使用facebook登錄對象在onClick按鈕上發帖
// this is the editext where i write my post
String messageFace = ((EditText) findViewById(R.id.message))
.getText().toString();
lf.postTextOnMyWall(messageFace);
我該怎麼做才能從我的牆上或公共頁面獲取Feed? 在此先感謝!
請給我完整的源代碼! – Divya